forked from MapComplete/MapComplete
Use IndexedDb to store cached geodata, fix #494. This should prevent crashes
This commit is contained in:
parent
8fa7de661e
commit
9c848cfaee
7 changed files with 94 additions and 147 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue