@stateloom/persist
v1.0.0-alpha.0
Published
Declarative state persistence with pluggable storage backends and async hydration.
Readme
@stateloom/persist
Declarative state persistence with pluggable storage backends and async hydration.
Install
pnpm add @stateloom/persistQuick Start
import { persist, localStorageBackend } from '@stateloom/persist';
import { createStore } from '@stateloom/store';
const persistMw = persist<{ count: number }>({
key: 'counter',
storage: localStorageBackend(),
});
const store = createStore(
(set) => ({
count: 0,
inc: () => set((s) => ({ count: s.count + 1 })),
}),
{ middleware: [persistMw] },
);Exports
| Export | Description |
| -------------------------- | ----------------------------------- |
| persist(options) | Persistence middleware factory |
| localStorageBackend() | localStorage storage adapter |
| sessionStorageBackend() | sessionStorage storage adapter |
| cookieStorage(options?) | Cookie-based storage adapter |
| indexedDBStorage(dbName) | IndexedDB async storage adapter |
| memoryStorage() | In-memory storage adapter (testing) |
| PERSIST_ERROR_CODE | Error code constants |
Documentation
Full documentation with API reference, migration patterns, and storage adapter guide: docs/api/persist
License
MIT
