Use IndexedDb to store cached geodata, fix #494. This should prevent crashes

This commit is contained in:
Pieter Vander Vennet 2021-11-16 02:57:26 +01:00
parent 8fa7de661e
commit 9c848cfaee
7 changed files with 94 additions and 147 deletions

View file

@ -8,12 +8,8 @@ export class IdbLocalStorage {
public static Get<T>(key: string, options: { defaultValue?: T }): UIEventSource<T>{
const src = new UIEventSource<T>(options.defaultValue, "idb-local-storage:"+key)
idb.get(key).then(v => {
src.setData(v ?? options.defaultValue)
})
src.stabilized(1000).addCallback(v => {
idb.set(key, v)
})
idb.get(key).then(v => src.setData(v ?? options.defaultValue))
src.addCallback(v => idb.set(key, v))
return src;
}
@ -22,4 +18,7 @@ export class IdbLocalStorage {
idb.set(key, value)
}
static GetDirectly(key: string) {
return idb.get(key)
}
}