@statesync/core
v1.1.0
Published
Framework-agnostic state synchronization engine with revision protocol
Maintainers
Readme
@statesync/core
Core state synchronization library. Framework- and transport-agnostic.
Install
npm install @statesync/coreQuick Start
import { createConsoleLogger, createRevisionSync } from '@statesync/core';
const handle = createRevisionSync({
topic: 'settings',
subscriber: myInvalidationSubscriber,
provider: mySnapshotProvider,
applier: {
apply(snapshot) {
console.log('New data:', snapshot.data);
},
},
onError(ctx) {
console.error(`[${ctx.phase}]`, ctx.error);
},
logger: createConsoleLogger({ debug: true }),
});
await handle.start();
// Later:
handle.stop();API
createRevisionSync<T>(options): RevisionSyncHandle
Creates a sync handle for the given topic.
Options:
topic— resource identifier (string)subscriber— invalidation event sourceprovider— snapshot providerapplier— applies snapshots to local stateshouldRefresh?— filter: whether to refresh for a specific eventlogger?— optional loggeronError?— error callback
Handle:
start()— subscribe and load the initial snapshotstop()— unsubscribe and block further applyrefresh()— one-shot fetch + applygetLocalRevision()— current local revision
See the lifecycle contract.
