Skip to main content

Store instance

Every store — however it was defined — has the same built-in members alongside its own state/getters/actions:

MemberSignatureSee
$idstringthe id passed to defineStore()
$stateproperty, get/setState
$patch(partialOrFn)(partial: DeepPartial<S>) => void or (fn: (state: S) => void) => voidState
$reset()() => void — schema stores only; throws for hooks storesState
$subscribe(callback, options?)(callback: (mutation, state: S) => void, options?: { detached?: boolean }) => () => voidSubscriptions & Action Hooks
$onAction(callback)(callback: (context: ActionListenerContext) => void) => () => voidSubscriptions & Action Hooks
$dispose()() => voidstops the store's internal reactivity and removes it from the Nekuta instance's registry — a later call to the same store definition rebuilds it fresh

$subscribe()/$onAction() both return an unsubscribe function.

SubscriptionCallbackMutation​

The first argument $subscribe()'s callback receives:

type SubscriptionCallbackMutation<S> = {
type: 'direct' | 'patch object' | 'patch function';
storeId: string;
};

ActionListenerContext​

The single argument $onAction()'s callback receives:

type ActionListenerContext = {
name: string; // the action's name
store: StoreGeneric;
args: unknown[]; // the arguments the action was called with
after: (callback: (result: unknown) => void) => void;
onError: (callback: (error: unknown) => void) => void;
};