@statesync/svelte
v2.0.0
Published
Svelte adapter for state-sync — automatic store synchronization
Downloads
182
Maintainers
Readme
@statesync/svelte
Svelte adapter for state-sync. Applies snapshots to a Svelte writable store.
Install
npm install @statesync/svelte @statesync/coreQuick Start
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();Modes
Patch (default)
const applier = createSvelteSnapshotApplier(store);
// Calls store.update(current => ({ ...current, ...patch }))Replace
const applier = createSvelteSnapshotApplier(store, { mode: 'replace' });
// Full replacement: deletes missing keys, assigns new onesOptions
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.
