@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
45 lines (44 loc) • 1.93 kB
text/typescript
import { c as PersistOptions, o as PersistApi } from "../persist-core-B649IGlX.mjs";
import { Action, Reducer, Store, UnknownAction } from "redux";
//#region src/adapters/sources/redux.d.ts
/**
* Wrap the root reducer so hydrate/`setState` can replace state. Do not wrap
* slices inside `combineReducers` — the payload is the full root. Without this,
* RTK slices ignore the private action (silent no-op). Named to avoid clashing
* with redux-persist's `persistReducer`.
*
* @example
* ```ts
* import { createStore } from "redux";
* import { persistableReducer } from "@stainless-code/persist/sources/redux";
* const store = createStore(persistableReducer(rootReducer));
* ```
*/
declare function persistableReducer<TState, TAction extends Action = UnknownAction>(baseReducer: Reducer<TState, TAction>): Reducer<TState, TAction>;
/**
* Persist a Redux store (classic `createStore` or RTK `configureStore`).
* Redux has no `setState` — hydrate/writes dispatch a private action handled
* by {@link persistableReducer} on the root. Do not use `replaceReducer` for
* hydrate.
*
* If you also import redux-persist's `persistStore`, alias this one:
* `import { persistStore as persistWithStainless } from "@stainless-code/persist/sources/redux"`.
*
* @example
* ```ts
* import { createStore } from "redux";
* import { createJSONStorage } from "@stainless-code/persist";
* import {
* persistStore,
* persistableReducer,
* } from "@stainless-code/persist/sources/redux";
* const store = createStore(persistableReducer(rootReducer));
* const persist = persistStore(store, {
* name: "root",
* storage: createJSONStorage(() => localStorage),
* });
* ```
*/
declare function persistStore<TState, TPersistedState = TState>(store: Store<TState>, options: PersistOptions<TState, TPersistedState>): PersistApi<TState, TPersistedState>;
//#endregion
export { persistStore, persistableReducer };