forked from MapComplete/MapComplete
Refactoring: re-enable caching
This commit is contained in:
parent
59544ec073
commit
476423f9d1
5 changed files with 19 additions and 3 deletions
|
@ -11,6 +11,7 @@ import { UIEventSource } from "../../UIEventSource"
|
||||||
export default class TileLocalStorage<T> {
|
export default class TileLocalStorage<T> {
|
||||||
private static perLayer: Record<string, TileLocalStorage<any>> = {}
|
private static perLayer: Record<string, TileLocalStorage<any>> = {}
|
||||||
private readonly _layername: string
|
private readonly _layername: string
|
||||||
|
private readonly inUse = new UIEventSource(false)
|
||||||
private readonly cachedSources: Record<number, UIEventSource<T> & { flush: () => void }> = {}
|
private readonly cachedSources: Record<number, UIEventSource<T> & { flush: () => void }> = {}
|
||||||
|
|
||||||
private constructor(layername: string) {
|
private constructor(layername: string) {
|
||||||
|
@ -49,7 +50,10 @@ export default class TileLocalStorage<T> {
|
||||||
|
|
||||||
private async SetIdb(tileIndex: number, data: any): Promise<void> {
|
private async SetIdb(tileIndex: number, data: any): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
await this.inUse.AsPromise((inUse) => !inUse)
|
||||||
|
this.inUse.setData(true)
|
||||||
await IdbLocalStorage.SetDirectly(this._layername + "_" + tileIndex, data)
|
await IdbLocalStorage.SetDirectly(this._layername + "_" + tileIndex, data)
|
||||||
|
this.inUse.setData(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(
|
console.error(
|
||||||
"Could not save tile to indexed-db: ",
|
"Could not save tile to indexed-db: ",
|
||||||
|
|
|
@ -240,6 +240,12 @@ export abstract class Store<T> implements Readable<T> {
|
||||||
return newSource
|
return newSource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the uiEventSource into a promise.
|
||||||
|
* The promise will return the value of the store if the given condition evaluates to true
|
||||||
|
* @param condition: an optional condition, default to 'store.value !== undefined'
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
public AsPromise(condition?: (t: T) => boolean): Promise<T> {
|
public AsPromise(condition?: (t: T) => boolean): Promise<T> {
|
||||||
const self = this
|
const self = this
|
||||||
condition = condition ?? ((t) => t !== undefined)
|
condition = condition ?? ((t) => t !== undefined)
|
||||||
|
|
|
@ -47,6 +47,7 @@ import ShowOverlayRasterLayer from "../UI/Map/ShowOverlayRasterLayer"
|
||||||
import { Utils } from "../Utils"
|
import { Utils } from "../Utils"
|
||||||
import { EliCategory } from "./RasterLayerProperties"
|
import { EliCategory } from "./RasterLayerProperties"
|
||||||
import BackgroundLayerResetter from "../Logic/Actors/BackgroundLayerResetter"
|
import BackgroundLayerResetter from "../Logic/Actors/BackgroundLayerResetter"
|
||||||
|
import SaveFeatureSourceToLocalStorage from "../Logic/FeatureSource/Actors/SaveFeatureSourceToLocalStorage"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -204,13 +205,13 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
this.perLayer = perLayer.perLayer
|
this.perLayer = perLayer.perLayer
|
||||||
}
|
}
|
||||||
this.perLayer.forEach((fs) => {
|
this.perLayer.forEach((fs) => {
|
||||||
/* TODO enable new SaveFeatureSourceToLocalStorage(
|
new SaveFeatureSourceToLocalStorage(
|
||||||
this.osmConnection.Backend(),
|
this.osmConnection.Backend(),
|
||||||
fs.layer.layerDef.id,
|
fs.layer.layerDef.id,
|
||||||
15,
|
15,
|
||||||
fs,
|
fs,
|
||||||
this.featureProperties
|
this.featureProperties
|
||||||
)//*/
|
)
|
||||||
|
|
||||||
const filtered = new FilteringFeatureSource(
|
const filtered = new FilteringFeatureSource(
|
||||||
fs.layer,
|
fs.layer,
|
||||||
|
|
|
@ -181,7 +181,7 @@ export default abstract class BaseUIElement {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
e.consumed = true
|
e.consumed = true
|
||||||
}
|
}
|
||||||
el.classList.add("pointer-events-none", "cursor-pointer")
|
el.classList.add("cursor-pointer")
|
||||||
}
|
}
|
||||||
|
|
||||||
return el
|
return el
|
||||||
|
|
|
@ -57,6 +57,11 @@ export abstract class Validator {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reformats for the human
|
||||||
|
* @param s
|
||||||
|
* @param country
|
||||||
|
*/
|
||||||
public reformat(s: string, country?: () => string): string {
|
public reformat(s: string, country?: () => string): string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue