Store instance
Every store — however it was defined — has the same built-in members alongside its own state/getters/actions:
| Member | Signature | See |
|---|---|---|
$id | string | the id passed to defineStore() |
$state | property, get/set | State |
$patch(partialOrFn) | (partial: DeepPartial<S>) => void or (fn: (state: S) => void) => void | State |
$reset() | () => void — schema stores only; throws for hooks stores | State |
$subscribe(callback, options?) | (callback: (mutation, state: S) => void, options?: { detached?: boolean }) => () => void | Subscriptions & Action Hooks |
$onAction(callback) | (callback: (context: ActionListenerContext) => void) => () => void | Subscriptions & Action Hooks |
$dispose() | () => void | stops 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;
};