Pinia adapter for state-sync — automatic store synchronization
npm install @statesync/piniaPinia adapter for state-sync. Applies snapshots to a Pinia store.
``bash`
npm install @statesync/pinia @statesync/core
`typescript
import { createRevisionSync } from '@statesync/core';
import { createPiniaSnapshotApplier } from '@statesync/pinia';
const store = useMyStore();
const applier = createPiniaSnapshotApplier(store);
const handle = createRevisionSync({
topic: 'settings',
subscriber: mySubscriber,
provider: myProvider,
applier,
});
await handle.start();
`
`typescript`
const applier = createPiniaSnapshotApplier(store);
// Calls store.$patch(data) — merges fields
`typescript`
const applier = createPiniaSnapshotApplier(store, { mode: 'replace' });
// Full replacement: deletes missing keys, assigns new ones
- toState(data, ctx) — map snapshot data → state patchpickKeys
- / omitKeys — limit which keys are updatedstrict
- (default: true) — throw if toState` returns a non-object
See full documentation.