@statesync/pinia
v2.0.0
Published
Pinia adapter for state-sync — automatic store synchronization
Maintainers
Readme
@statesync/pinia
Pinia adapter for state-sync. Applies snapshots to a Pinia store.
Install
npm install @statesync/pinia @statesync/coreQuick Start
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();Modes
Patch (default)
const applier = createPiniaSnapshotApplier(store);
// Calls store.$patch(data) — merges fieldsReplace
const applier = createPiniaSnapshotApplier(store, { mode: 'replace' });
// Full replacement: deletes missing keys, assigns new onesOptions
toState(data, ctx)— map snapshot data → state patchpickKeys/omitKeys— limit which keys are updatedstrict(default:true) — throw iftoStatereturns a non-object
See full documentation.
