mapcomplete/Logic/LocalStorageSource.ts

17 lines
519 B
TypeScript
Raw Normal View History

import {UIEventSource} from "../UI/UIEventSource";
export class LocalStorageSource {
static Get(key: string, defaultValue: string = undefined): UIEventSource<string> {
2020-07-25 16:00:08 +00:00
const saved = localStorage.getItem(key);
const source = new UIEventSource<string>(saved ?? defaultValue);
2020-07-25 16:00:08 +00:00
// ignore when running from the console
source.addCallback((data) => {
localStorage.setItem(key, data);
console.log("Wriging ", key, data)
});
return source;
}
}