forked from MapComplete/MapComplete
Lots of refactoring, first version of the import helper
This commit is contained in:
parent
612b8136ad
commit
3402ac0954
54 changed files with 1104 additions and 315 deletions
|
@ -8,12 +8,17 @@ import {Utils} from "../../Utils";
|
|||
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)
|
||||
public static Get<T>(key: string, options?: { defaultValue?: T , whenLoaded?: (t: T) => void}): UIEventSource<T>{
|
||||
const src = new UIEventSource<T>(options?.defaultValue, "idb-local-storage:"+key)
|
||||
if(Utils.runningFromConsole){
|
||||
return src;
|
||||
}
|
||||
idb.get(key).then(v => src.setData(v ?? options.defaultValue))
|
||||
idb.get(key).then(v => {
|
||||
src.setData(v ?? options?.defaultValue);
|
||||
if(options?.whenLoaded !== undefined){
|
||||
options?.whenLoaded(v)
|
||||
}
|
||||
})
|
||||
src.addCallback(v => idb.set(key, v))
|
||||
return src;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue