forked from MapComplete/MapComplete
WIP: use indexedDB as datastore for geotiles
This commit is contained in:
parent
b5693304f2
commit
8fa7de661e
9 changed files with 99 additions and 65 deletions
25
Logic/Web/IdbLocalStorage.ts
Normal file
25
Logic/Web/IdbLocalStorage.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import {UIEventSource} from "../UIEventSource";
|
||||
import * as idb from "idb-keyval"
|
||||
/**
|
||||
* UIEventsource-wrapper around indexedDB key-value
|
||||
*/
|
||||
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)
|
||||
})
|
||||
return src;
|
||||
|
||||
}
|
||||
|
||||
public static SetDirectly(key: string, value){
|
||||
idb.set(key, value)
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue