forked from MapComplete/MapComplete
Add current location in localstorage, fixes #13
This commit is contained in:
parent
2a61ae6e1f
commit
89b78ee709
5 changed files with 28 additions and 25 deletions
15
Logic/LocalStorageSource.ts
Normal file
15
Logic/LocalStorageSource.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import {UIEventSource} from "../UI/UIEventSource";
|
||||
|
||||
export class LocalStorageSource {
|
||||
|
||||
static Get(key: string, defaultValue: string = undefined): UIEventSource<string> {
|
||||
const saved = localStorage.getItem(key);
|
||||
const source = new UIEventSource<string>(saved ?? defaultValue);
|
||||
|
||||
source.addCallback((data) => {
|
||||
localStorage.setItem(key, data);
|
||||
console.log("Wriging ", key, data)
|
||||
});
|
||||
return source;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue