Svelte adapter for state-sync — automatic store synchronization
npm install @statesync/svelteSvelte adapter for state-sync. Applies snapshots to a Svelte writable store.
``bash`
npm install @statesync/svelte @statesync/core
`typescript
import { createRevisionSync } from '@statesync/core';
import { createSvelteSnapshotApplier } from '@statesync/svelte';
import { writable } from 'svelte/store';
const settings = writable({ theme: 'light', lang: 'en' });
const applier = createSvelteSnapshotApplier(settings);
const handle = createRevisionSync({
topic: 'settings',
subscriber: mySubscriber,
provider: myProvider,
applier,
});
await handle.start();
`
`typescript`
const applier = createSvelteSnapshotApplier(store);
// Calls store.update(current => ({ ...current, ...patch }))
`typescript`
const applier = createSvelteSnapshotApplier(store, { mode: 'replace' });
// Full replacement: deletes missing keys, assigns new ones
- toState(data, ctx) — map snapshot data to state patchpickKeys
- / omitKeys — limit which keys are updatedstrict
- (default: true) — throw if toState` returns a non-object
See full documentation.