@statesync/valtio
v2.0.0
Published
Valtio adapter for state-sync — automatic proxy synchronization
Maintainers
Readme
@statesync/valtio
Valtio adapter for state-sync. Applies snapshots to a Valtio proxy.
Install
npm install @statesync/valtio @statesync/coreQuick Start
import { createRevisionSync } from '@statesync/core';
import { createValtioSnapshotApplier } from '@statesync/valtio';
import { proxy } from 'valtio';
const state = proxy({ theme: 'light', lang: 'en' });
const applier = createValtioSnapshotApplier(state);
const handle = createRevisionSync({
topic: 'settings',
subscriber: mySubscriber,
provider: myProvider,
applier,
});
await handle.start();Modes
Patch (default)
const applier = createValtioSnapshotApplier(state);
// Assigns filtered keys directly on the proxyReplace
const applier = createValtioSnapshotApplier(state, { mode: 'replace' });
// Deletes allowed keys not in new state, then assigns new keysNotes
- The proxy reference is never replaced — mutations are applied directly
- Existing Valtio subscribers (useSnapshot) continue to work
Options
toState(data, ctx)— map snapshot data to state patchpickKeys/omitKeys— limit which keys are updatedstrict(default:true) — throw iftoStatereturns a non-object
See full documentation.
