Files
welshman/packages/store/src/synced.ts
T
2025-04-25 10:37:57 -07:00

12 lines
317 B
TypeScript

import {writable} from "svelte/store"
import {getJson, setJson} from "@welshman/lib"
export const synced = <T>(key: string, defaultValue: T) => {
const init = getJson(key)
const store = writable<T>(init === undefined ? defaultValue : init)
store.subscribe((value: T) => setJson(key, value))
return store
}