From 476423f9d168c366eac48145dc80527151369a5d Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 21 Apr 2023 20:50:38 +0200 Subject: [PATCH] Refactoring: re-enable caching --- Logic/FeatureSource/Actors/TileLocalStorage.ts | 4 ++++ Logic/UIEventSource.ts | 6 ++++++ Models/ThemeViewState.ts | 5 +++-- UI/BaseUIElement.ts | 2 +- UI/InputElement/Validator.ts | 5 +++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Logic/FeatureSource/Actors/TileLocalStorage.ts b/Logic/FeatureSource/Actors/TileLocalStorage.ts index dc92acf855..22e7dbb031 100644 --- a/Logic/FeatureSource/Actors/TileLocalStorage.ts +++ b/Logic/FeatureSource/Actors/TileLocalStorage.ts @@ -11,6 +11,7 @@ import { UIEventSource } from "../../UIEventSource" export default class TileLocalStorage { private static perLayer: Record> = {} private readonly _layername: string + private readonly inUse = new UIEventSource(false) private readonly cachedSources: Record & { flush: () => void }> = {} private constructor(layername: string) { @@ -49,7 +50,10 @@ export default class TileLocalStorage { private async SetIdb(tileIndex: number, data: any): Promise { 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: ", diff --git a/Logic/UIEventSource.ts b/Logic/UIEventSource.ts index 4a16550fff..6aa823055c 100644 --- a/Logic/UIEventSource.ts +++ b/Logic/UIEventSource.ts @@ -240,6 +240,12 @@ export abstract class Store implements Readable { 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 { const self = this condition = condition ?? ((t) => t !== undefined) diff --git a/Models/ThemeViewState.ts b/Models/ThemeViewState.ts index 53b8099aeb..5f71ce78e5 100644 --- a/Models/ThemeViewState.ts +++ b/Models/ThemeViewState.ts @@ -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, diff --git a/UI/BaseUIElement.ts b/UI/BaseUIElement.ts index 94a9764763..601218a91e 100644 --- a/UI/BaseUIElement.ts +++ b/UI/BaseUIElement.ts @@ -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 diff --git a/UI/InputElement/Validator.ts b/UI/InputElement/Validator.ts index 858622ebe8..5ad93b8829 100644 --- a/UI/InputElement/Validator.ts +++ b/UI/InputElement/Validator.ts @@ -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 }