aboutsummaryrefslogtreecommitdiff
path: root/src/stores/stateBin.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-06-12 22:06:31 -0700
committerFuwn <[email protected]>2025-06-12 22:06:31 -0700
commite8612618fb20f779ebe2e85edf32d71961d2f1d4 (patch)
treefa8565afb8584bbf55f4f4d496c2c350a5a25210 /src/stores/stateBin.ts
parentrefactor(List): Simplify get-set structure of stateBin usage (diff)
downloaddue.moe-e8612618fb20f779ebe2e85edf32d71961d2f1d4.tar.xz
due.moe-e8612618fb20f779ebe2e85edf32d71961d2f1d4.zip
feat: Move remaining localStorage usages to localforage
Diffstat (limited to 'src/stores/stateBin.ts')
-rw-r--r--src/stores/stateBin.ts15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/stores/stateBin.ts b/src/stores/stateBin.ts
index 74ea510f..082a07dc 100644
--- a/src/stores/stateBin.ts
+++ b/src/stores/stateBin.ts
@@ -1,17 +1,22 @@
import { browser } from '$app/environment';
import { writable, get, type Writable } from 'svelte/store';
+import localforage from 'localforage';
type StateBin = Record<string, unknown>;
const STORAGE_KEY = 'stateBin';
-const initialState = browser ? JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '{}') : {};
-const baseStore = writable<StateBin>(initialState);
+const baseStore = writable<StateBin>({});
-if (browser)
- baseStore.subscribe((val) => {
- localStorage.setItem(STORAGE_KEY, JSON.stringify(val));
+if (browser) {
+ localforage.getItem<StateBin>(STORAGE_KEY).then((value) => {
+ if (value && typeof value === 'object') baseStore.set(value);
});
+ baseStore.subscribe((value) => {
+ localforage.setItem(STORAGE_KEY, value);
+ });
+}
+
const createProxyStore = (store: Writable<StateBin>) => {
return new Proxy(store, {
get(target, prop: string) {