Skip to content

@statesync/core


@statesync/core / SnapshotApplier

Interface: SnapshotApplier<T> ​

Defined in: types.ts:181

Applies a fetched snapshot to local state.

The engine calls apply after successfully fetching a snapshot that is newer than the current local revision.

Example ​

ts
const applier: SnapshotApplier<UserProfile> = {
  apply({ revision, data }) {
    store.setState({ profile: data });
  },
};

Type Parameters ​

Type ParameterDescription
TThe application-specific snapshot data type.

Methods ​

apply() ​

ts
apply(snapshot): void | Promise<void>;

Defined in: types.ts:191

Applies the given snapshot to local state.

May be synchronous or asynchronous. If it returns a promise, the engine will await it before advancing the local revision.

Parameters ​

ParameterTypeDescription
snapshotSnapshotEnvelope<T>The SnapshotEnvelope containing the revision and payload to apply.

Returns ​

void | Promise<void>

Throws ​

If the local state update fails.

Released under the MIT License.