Refactoring: tweak some featuresources to allow them to run in the tests

This commit is contained in:
Pieter Vander Vennet 2023-05-17 13:19:43 +02:00
parent ad1178df6c
commit 39aff86c76
3 changed files with 15 additions and 4 deletions

View file

@ -14,6 +14,7 @@ export default class TileLocalStorage<T> {
private readonly inUse = new UIEventSource(false)
private readonly cachedSources: Record<number, UIEventSource<T> & { flush: () => void }> = {}
private static readonly useIndexedDb = typeof indexedDB !== "undefined"
private constructor(layername: string) {
this._layername = layername
}
@ -49,6 +50,9 @@ export default class TileLocalStorage<T> {
}
private async SetIdb(tileIndex: number, data: any): Promise<void> {
if(!TileLocalStorage.useIndexedDb){
return
}
try {
await this.inUse.AsPromise((inUse) => !inUse)
this.inUse.setData(true)
@ -69,6 +73,9 @@ export default class TileLocalStorage<T> {
}
private GetIdb(tileIndex: number): Promise<any> {
if(!TileLocalStorage.useIndexedDb){
return undefined
}
return IdbLocalStorage.GetDirectly(this._layername + "_" + tileIndex)
}
}