Rxova
Skip to content

PersistOptions

adapter: PersistAdapter;

optional debounceMs?: number;

Coalesce writes for this long. Default 100.


optional keys?: string[];

Persist only these keys. Default: every key that has been written.


optional migrate?: (state, from) => Record<string, unknown>;

Bring persisted state written at an older version up to the current one. Return the migrated state; the version clocks are carried over untouched, so a migrated value keeps its place in the last-writer-wins order.

Only called when from is older. Newer data — an older build reading what a newer one wrote — is refused instead, because a build cannot be asked to understand a shape that postdates it. That is the same call the wire makes for a protocol version it does not know.

ParameterType
stateRecord<string, unknown>
fromnumber

Record<string, unknown>


optional onRestoreError?: (error) => void;

Called when persisted state is refused instead of restored. The store keeps its initial values and carries on either way — this is how you find out, and the default is a development warning.

ParameterType
errorRestoreError

void


optional version?: number;

The version of your state’s shape. Bump it whenever a key changes meaning or type, and supply migrate to carry old data forward.

Disk is where version skew has its longest fuse. A wire from another deploy is gone in a second; a value written by last month’s build sits there until someone reopens the tab, and then restores with a clock that beats every live tab. Without a version there is no way to even notice.

Default 0, which is also what anything written before this existed reads as — so adding version: 1 and a migrate is enough to adopt it.