UNPKG

@stainless-code/persist

Version:

Hydration-aware persistence for any reactive store — zero-dep persistSource core; codecs, backends, cross-tab transport, source + framework hydration adapters ship as opt-in recipes

38 lines (37 loc) • 1.61 kB
import { c as PersistOptions, o as PersistApi } from "../persist-core-B649IGlX.mjs"; import { Atom, Store, StoreActionMap } from "@tanstack/store"; //#region src/adapters/sources/tanstack-store.d.ts /** * Persist a `@tanstack/store` `Store` (action-bearing stores included). * * @example * ```ts * const store = new Store({ filters: [] as string[] }); * const persist = persistStore(store, { * name: "app:filters:v1", * version: 1, * skipPersist: (s) => s.filters.length === 0, // no key when default * }); * // hydrates automatically on create; subscribe-writes on every setState * await persist.rehydrate(); // optional manual re-read, awaitable * ``` */ declare function persistStore<TState, TPersistedState = TState>(store: Store<TState, StoreActionMap>, options: PersistOptions<TState, TPersistedState>): PersistApi<TState, TPersistedState>; /** * Persist a writable `@tanstack/store` `Atom`. Default `merge` REPLACES * instead of shallow-spreading — atoms commonly hold primitives, which a * spread would corrupt. Pass `merge` to override. * * @throws Error when given a readonly (computed) atom — there is no `set` to * hydrate into. * * @example * ```ts * const theme = createAtom<"light" | "dark">("light"); * const persist = persistAtom(theme, { name: "app:theme:v1" }); * // hydrate REPLACES the primitive; theme.set() writes through * ``` */ declare function persistAtom<TState, TPersistedState = TState>(atom: Atom<TState>, options: PersistOptions<TState, TPersistedState>): PersistApi<TState, TPersistedState>; //#endregion export { persistAtom, persistStore };