Framework-agnostic state synchronization engine with revision protocol
npm install @statesync/coreCore state synchronization library. Framework- and transport-agnostic.
``bash`
npm install @statesync/core
`typescript
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();
`
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.