Skip to content

@statesync/jotai


@statesync/jotai / JotaiSnapshotApplierOptions

Type Alias: JotaiSnapshotApplierOptions<State, Data> ​

ts
type JotaiSnapshotApplierOptions<State, Data> = 
  | {
  mode?: "patch";
  omitKeys?: ReadonlyArray<keyof State>;
  pickKeys?: ReadonlyArray<keyof State>;
  strict?: boolean;
  toState?: (data, ctx) => Partial<State>;
}
  | {
  mode: "replace";
  omitKeys?: ReadonlyArray<keyof State>;
  pickKeys?: ReadonlyArray<keyof State>;
  strict?: boolean;
  toState?: (data, ctx) => State;
};

Defined in: jotai.ts:80

Configuration options for createJotaiSnapshotApplier.

This is a discriminated union on the mode field:

  • When mode is 'patch' (or omitted), toState is expected to return Partial<State>.
  • When mode is 'replace', toState is expected to return the full State.

Type Parameters ​

Type ParameterDescription
State extends Record<string, unknown>The value type of the atom.
DataThe snapshot payload type received from the sync engine. Defaults to State when the snapshot data matches the atom value shape directly.

Type Declaration ​

ts
{
  mode?: "patch";
  omitKeys?: ReadonlyArray<keyof State>;
  pickKeys?: ReadonlyArray<keyof State>;
  strict?: boolean;
  toState?: (data, ctx) => Partial<State>;
}

mode? ​

ts
optional mode: "patch";

The apply strategy. Defaults to 'patch'.

Default Value ​

'patch'

omitKeys? ​

ts
optional omitKeys: ReadonlyArray<keyof State>;

pickKeys? ​

ts
optional pickKeys: ReadonlyArray<keyof State>;

strict? ​

ts
optional strict: boolean;

When true, the applier throws if toState returns a non-plain-object value. When false, such values are silently ignored.

Default Value ​

true

toState()? ​

ts
optional toState: (data, ctx) => Partial<State>;

Maps raw snapshot data to a state patch object.

Parameters ​

ParameterTypeDescription
dataDataThe raw snapshot payload from the sync engine.
ctx{ atom: unknown; store: JotaiStoreLike<State, unknown>; }Context object providing access to the target store and atom.
ctx.atomunknown-
ctx.storeJotaiStoreLike<State, unknown>-

Returns ​

Partial<State>

A partial state object to be shallow-merged into the atom.

Default Value ​

Identity cast — treats data as Partial<State>.

ts
{
  mode: "replace";
  omitKeys?: ReadonlyArray<keyof State>;
  pickKeys?: ReadonlyArray<keyof State>;
  strict?: boolean;
  toState?: (data, ctx) => State;
}

mode ​

ts
mode: "replace";

Use 'replace' mode for an atomic full-state swap.

omitKeys? ​

ts
optional omitKeys: ReadonlyArray<keyof State>;

pickKeys? ​

ts
optional pickKeys: ReadonlyArray<keyof State>;

strict? ​

ts
optional strict: boolean;

When true, the applier throws if toState returns a non-plain-object value. When false, such values are silently ignored.

Default Value ​

true

toState()? ​

ts
optional toState: (data, ctx) => State;

Maps raw snapshot data to the full next state.

Parameters ​

ParameterTypeDescription
dataDataThe raw snapshot payload from the sync engine.
ctx{ atom: unknown; store: JotaiStoreLike<State, unknown>; }Context object providing access to the target store and atom.
ctx.atomunknown-
ctx.storeJotaiStoreLike<State, unknown>-

Returns ​

State

The full next state to replace the current atom value with.

Default Value ​

Identity cast — treats data as State.

Released under the MIT License.