mapcomplete/Logic/LocalStorageSource.ts
2020-07-24 17:53:09 +02:00

15 lines
No EOL
470 B
TypeScript

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;
}
}