forked from MapComplete/MapComplete
Some refactoring, more work on the custom theme generator
This commit is contained in:
parent
c4b5f180a6
commit
146552e62c
104 changed files with 382 additions and 1590 deletions
21
Logic/Web/LocalStorageSource.ts
Normal file
21
Logic/Web/LocalStorageSource.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import {UIEventSource} from "../UIEventSource";
|
||||
|
||||
export class LocalStorageSource {
|
||||
|
||||
static Get(key: string, defaultValue: string = undefined): UIEventSource<string> {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
const saved = localStorage.getItem(key);
|
||||
const source = new UIEventSource<string>(saved ?? defaultValue);
|
||||
|
||||
source.addCallback((data) => {
|
||||
localStorage.setItem(key, data);
|
||||
});
|
||||
return source;
|
||||
} catch (e) {
|
||||
return new UIEventSource<string>(defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue