@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
22 lines (21 loc) • 1.03 kB
text/typescript
import { c as PersistOptions, o as PersistApi } from "../persist-core-B649IGlX.mjs";
import { Store, StoreState } from "pinia";
//#region src/adapters/sources/pinia.d.ts
/**
* Persist a Pinia store. Hydrate via `$state =` (shallow assign), not object
* `$patch`. Subscribe with `{ detached: true }` so the listener outlives the
* effect scope.
*
* @example
* ```ts
* import { defineStore } from "pinia";
* import { createJSONStorage } from "@stainless-code/persist";
* import { persistStore } from "@stainless-code/persist/sources/pinia";
* const useCountStore = defineStore("count", { state: () => ({ count: 0 }) });
* const store = useCountStore();
* const persist = persistStore(store, { name: "count", storage: createJSONStorage(() => localStorage) });
* ```
*/
declare function persistStore<TStore extends Store, TPersistedState = StoreState<TStore>>(store: TStore, options: PersistOptions<StoreState<TStore>, TPersistedState>): PersistApi<StoreState<TStore>, TPersistedState>;
//#endregion
export { persistStore };