WIP: use indexedDB as datastore for geotiles

This commit is contained in:
Pieter Vander Vennet 2021-11-15 11:51:32 +01:00
parent b5693304f2
commit 8fa7de661e
9 changed files with 99 additions and 65 deletions

View 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)
}
}