resetMachine
resetMachine<
T>(machine:T&Partial<{reset: () =>void; }>,state:FactoryKeyedState<ReturnType<T["getState"]>>,type:string):void
Defined in: extras/with-reset.ts:15
Resets a state machine to a given state by performing a transition.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
T extends StateMachine<any> | Type of StateMachine |
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
machine | T & Partial<{ reset: () => void; }> | undefined | The state machine instance (optionally with a reset method) |
state | FactoryKeyedState<ReturnType<T["getState"]>> | undefined | The state to reset to |
type | string | "reset" | The transition type (default: “reset”) |
Returns
Section titled “Returns”void
Source
Section titled “Source”This function is useful for programmatically resetting a state machine to a known state, enabling repeatable workflows, error recovery, or test setup. It provides a generic way to trigger a reset transition and is foundational for adding reset capabilities to state machines.
export const resetMachine = <T extends StateMachine<any>>( machine: T & Partial<{ reset: () => void }>, state: FactoryKeyedState<ReturnType<T["getState"]>>, type = "reset") => { const before = machine.getChange(); machine.transition({ from: before.to, type, to: state, } as any);};