createReset
createReset<
T
>(machine
:T
,state
:FactoryKeyedState
<ReturnType
<T
["getState"
]>>): () =>void
Defined in: extras/with-reset.ts:44
Creates a reset function for a state machine, resetting it to a given state. Usage:
const reset = createReset(machine, "Idle");reset(); // Resets the machine to the "Idle" state
Type Parameters
Section titled “Type Parameters”Type Parameter | Description |
---|---|
T extends StateMachine <any > | Type of StateMachine |
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
machine | T | The state machine instance |
state | FactoryKeyedState <ReturnType <T ["getState" ]>> | The state to reset to |
Returns
Section titled “Returns”A function that resets the machine to the specified state
():
void
Returns
Section titled “Returns”void
Source
Section titled “Source”This function is useful for generating a reusable reset function for a state machine, allowing you to reset the machine to a specific state on demand. It is commonly used in scenarios where you want to expose a reset API or automate state restoration.
export const createReset = <T extends StateMachine<any>>( machine: T, state: FactoryKeyedState<ReturnType<T["getState"]>> ) => () => { resetMachine(machine, state); };