Skip to content

@statesync/persistence


@statesync/persistence / PersistenceEvents

Interface: PersistenceEvents<T>

Defined in: persistence/src/types.ts:428

Map of persistence lifecycle event names to their handler signatures.

Subscribe to these events via DisposablePersistenceApplier.on to observe save/load activity, errors, and cache management events.

Type Parameters

Type ParameterDescription
TThe shape of the application state.

Properties

cleared()

ts
cleared: () => void;

Defined in: persistence/src/types.ts:480

Emitted when persisted data is cleared from storage.

Returns

void


expired()

ts
expired: (snapshot, age) => void;

Defined in: persistence/src/types.ts:468

Emitted when a cached snapshot is discarded because its TTL has expired.

Parameters

ParameterTypeDescription
snapshotSnapshotEnvelope<T>The expired snapshot.
agenumberHow old the snapshot was in milliseconds when it expired.

Returns

void


loadComplete()

ts
loadComplete: (snapshot, durationMs) => void;

Defined in: persistence/src/types.ts:460

Emitted when a load operation completes (successfully or with no data).

Parameters

ParameterTypeDescription
snapshotSnapshotEnvelope<T> | nullThe loaded snapshot, or null if nothing was stored.
durationMsnumberWall-clock time the load took, in milliseconds.

Returns

void


migrated()

ts
migrated: (result) => void;

Defined in: persistence/src/types.ts:475

Emitted when persisted data is successfully migrated to a newer schema version.

Parameters

ParameterTypeDescription
resultMigrationResult<T>The migration result including source/target versions and migrated data.

Returns

void


saveComplete()

ts
saveComplete: (snapshot, durationMs) => void;

Defined in: persistence/src/types.ts:442

Emitted when a save operation completes successfully.

Parameters

ParameterTypeDescription
snapshotSnapshotEnvelope<T>The snapshot that was persisted.
durationMsnumberWall-clock time the save took, in milliseconds.

Returns

void


saveError()

ts
saveError: (error, snapshot) => void;

Defined in: persistence/src/types.ts:452

Emitted when a save operation fails.

The inner applier still receives the snapshot -- only persistence is affected.

Parameters

ParameterTypeDescription
errorunknownThe error thrown by the storage backend.
snapshotSnapshotEnvelope<T>The snapshot that failed to persist.

Returns

void


saveStart()

ts
saveStart: (snapshot) => void;

Defined in: persistence/src/types.ts:434

Emitted when a save operation begins, before data is written to storage.

Parameters

ParameterTypeDescription
snapshotSnapshotEnvelope<T>The snapshot about to be persisted.

Returns

void

Released under the MIT License.