import {UIEventSource} from "../UIEventSource"; export class LocalStorageSource { static Get(key: string, defaultValue: string = undefined): UIEventSource { try { const saved = localStorage.getItem(key); const source = new UIEventSource(saved ?? defaultValue, "localstorage:"+key); source.addCallback((data) => { localStorage.setItem(key, data); }); return source; } catch (e) { return new UIEventSource(defaultValue); } } }