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> {
|
||||
private static perLayer: Record<string, TileLocalStorage<any>> = {}
|
||||
private readonly _layername: string
|
||||
private readonly inUse = new UIEventSource(false)
|
||||
private readonly cachedSources: Record<number, UIEventSource<T> & { flush: () => void }> = {}
|
||||
|
||||
private constructor(layername: string) {
|
||||
|
@ -49,7 +50,10 @@ export default class TileLocalStorage<T> {
|
|||
|
||||
private async SetIdb(tileIndex: number, data: any): Promise<void> {
|
||||
try {
|
||||
await this.inUse.AsPromise((inUse) => !inUse)
|
||||
this.inUse.setData(true)
|
||||
await IdbLocalStorage.SetDirectly(this._layername + "_" + tileIndex, data)
|
||||
this.inUse.setData(false)
|
||||
} catch (e) {
|
||||
console.error(
|
||||
"Could not save tile to indexed-db: ",
|
||||
|
|
|
@ -240,6 +240,12 @@ export abstract class Store<T> implements Readable<T> {
|
|||
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> {
|
||||
const self = this
|
||||
condition = condition ?? ((t) => t !== undefined)
|
||||
|
|
|
@ -47,6 +47,7 @@ import ShowOverlayRasterLayer from "../UI/Map/ShowOverlayRasterLayer"
|
|||
import { Utils } from "../Utils"
|
||||
import { EliCategory } from "./RasterLayerProperties"
|
||||
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.forEach((fs) => {
|
||||
/* TODO enable new SaveFeatureSourceToLocalStorage(
|
||||
new SaveFeatureSourceToLocalStorage(
|
||||
this.osmConnection.Backend(),
|
||||
fs.layer.layerDef.id,
|
||||
15,
|
||||
fs,
|
||||
this.featureProperties
|
||||
)//*/
|
||||
)
|
||||
|
||||
const filtered = new FilteringFeatureSource(
|
||||
fs.layer,
|
||||
|
|
|
@ -181,7 +181,7 @@ export default abstract class BaseUIElement {
|
|||
// @ts-ignore
|
||||
e.consumed = true
|
||||
}
|
||||
el.classList.add("pointer-events-none", "cursor-pointer")
|
||||
el.classList.add("cursor-pointer")
|
||||
}
|
||||
|
||||
return el
|
||||
|
|
|
@ -57,6 +57,11 @@ export abstract class Validator {
|
|||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Reformats for the human
|
||||
* @param s
|
||||
* @param country
|
||||
*/
|
||||
public reformat(s: string, country?: () => string): string {
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue