aboutsummaryrefslogtreecommitdiff
path: root/src/stores/stateBin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/stateBin.ts')
-rw-r--r--src/stores/stateBin.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/stores/stateBin.ts b/src/stores/stateBin.ts
index 06d34bef..1d3f5dee 100644
--- a/src/stores/stateBin.ts
+++ b/src/stores/stateBin.ts
@@ -13,14 +13,22 @@ interface StateBin {
const STORAGE_KEY = "stateBin";
const baseStore = writable<StateBin>({});
+let hydrated = !browser;
+let state: StateBin = {};
if (browser) {
localforage.getItem<StateBin>(STORAGE_KEY).then((value) => {
if (value && typeof value === "object") baseStore.set(value);
+
+ hydrated = true;
+
+ localforage.setItem(STORAGE_KEY, state);
});
baseStore.subscribe((value) => {
- localforage.setItem(STORAGE_KEY, value);
+ state = value;
+
+ if (hydrated) localforage.setItem(STORAGE_KEY, value);
});
}