Skip to content

@sqlrooms/room-shell / PersistenceController

Type Alias: PersistenceController<TSnapshot>

PersistenceController<TSnapshot> = object

Type Parameters

Type Parameter
TSnapshot

Properties

hydrate

hydrate: () => Promise<TSnapshot | null>

Loads the adapter snapshot and treats it as the saved snapshot.

Hydration does not mark the controller dirty. Hosts should merge the loaded snapshot into their runtime store, then call markSnapshotSaved if the merged runtime shape differs from the raw loaded snapshot.

Returns

Promise<TSnapshot | null>


markSnapshotSaved

markSnapshotSaved: (snapshot) => void

Marks a snapshot as clean without writing it.

Use this after hydration or other trusted reconciliation work once runtime state reflects durable storage and should not be interpreted as a user edit.

Parameters

ParameterType
snapshotTSnapshot | null

Returns

void


setSnapshot

setSnapshot: (snapshot, reason?) => void

Provides the latest snapshot to save and marks it dirty when it differs from the saved snapshot.

Parameters

ParameterType
snapshotTSnapshot
reason?PersistenceSaveReason

Returns

void


markDirty

markDirty: (reason?) => void

Marks the current getSnapshot result dirty without providing it eagerly.

Parameters

ParameterType
reason?PersistenceSaveReason

Returns

void


saveNow

saveNow: (reason?) => Promise<void>

Saves the dirty snapshot immediately, bypassing autosave delay.

Parameters

ParameterType
reason?PersistenceSaveReason

Returns

Promise<void>


flush

flush: (reason?) => Promise<void>

Flushes pending dirty state before unload, close, or project switch.

Parameters

ParameterType
reason?PersistenceSaveReason

Returns

Promise<void>


pause

pause: <TResult>(fn) => Promise<TResult>

Runs work while dirty marking and snapshot updates are ignored.

Use this around hydration or programmatic restore flows that should not be treated as user edits.

Type Parameters

Type Parameter
TResult

Parameters

ParameterType
fn() => TResult | Promise<TResult>

Returns

Promise<TResult>


getState

getState: () => PersistenceControllerState

Returns a copy of the current observable controller state.

Returns

PersistenceControllerState


subscribe

subscribe: (listener) => () => void

Subscribes to observable controller state changes.

Parameters

ParameterType
listenerPersistenceControllerListener

Returns

() => void