Skip to content

FactoryMachine

Defined in: factory-machine-types.ts:41

FactoryMachine is a type-safe state machine that uses a state factory and transitions. It extends the StateMachine interface to provide additional functionality specific to factory-based state machines.

See also:

Type ParameterDefault type
FC extends FactoryMachineContext<any>FactoryMachineContext

transition(change: FactoryMachineEvent): void

Defined in: event-lifecycle.ts:28

Triggers the transition lifecycle, handling all steps for processing a change event.

ParameterType
changeFactoryMachineEvent

void

Omit.transition


guard(ev: FactoryMachineEvent): boolean

Defined in: event-lifecycle.ts:32

Checks if a transition event is allowed to proceed. Returns true to continue, false to abort.

ParameterType
evFactoryMachineEvent

boolean

Omit.guard


handle(ev: FactoryMachineEvent): undefined | FactoryMachineEvent<FC>

Defined in: event-lifecycle.ts:36

Processes the event. May abort the transition if returns undefined.

ParameterType
evFactoryMachineEvent

undefined | FactoryMachineEvent<FC>

Omit.handle


before(ev: FactoryMachineEvent): undefined | FactoryMachineEvent<FC>

Defined in: event-lifecycle.ts:41

Called before the transition is applied. May abort if returns undefined. (Represents a beforeTransition hook, not state entry/exit.)

ParameterType
evFactoryMachineEvent

undefined | FactoryMachineEvent<FC>

Omit.before


update(ev: FactoryMachineEvent): void

Defined in: event-lifecycle.ts:45

Applies the state update.

ParameterType
evFactoryMachineEvent

void

Omit.update


effect(ev: FactoryMachineEvent): void

Defined in: event-lifecycle.ts:49

Runs side effects for the transition. By default, calls leave and enter hooks.

ParameterType
evFactoryMachineEvent

void

Omit.effect


leave(ev: FactoryMachineEvent): void

Defined in: event-lifecycle.ts:53

Called when leaving the previous state.

ParameterType
evFactoryMachineEvent

void

Omit.leave


enter(ev: FactoryMachineEvent): void

Defined in: event-lifecycle.ts:57

Called when entering the new state.

ParameterType
evFactoryMachineEvent

void

Omit.enter


notify(ev: FactoryMachineEvent): void

Defined in: event-lifecycle.ts:61

Notifies subscribers of the change.

ParameterType
evFactoryMachineEvent

void

Omit.notify


after(ev: FactoryMachineEvent): void

Defined in: event-lifecycle.ts:65

Final hook after transition completes. (Represents afterTransition, not state entry/exit.)

ParameterType
evFactoryMachineEvent

void

Omit.after


send<T>(type: T, …params: ExtractEventParams<FC, T>): void

Defined in: factory-machine-types.ts:54

Send an event to the state machine with strongly typed parameters based on the event type. This overrides the base StateMachine send method to provide better type checking.

Type Parameter
T extends string
ParameterTypeDescription
typeTThe event type to send
paramsExtractEventParams<FC, T>The parameters for the event, typed based on the event type

void


getState(): FactoryMachineEvent<FC>["to"] | FactoryMachineEvent<FC>["from"]

Defined in: state-machine.ts:31

Returns the current state of the machine (the to property of the last change).

FactoryMachineEvent<FC>["to"] | FactoryMachineEvent<FC>["from"]

Omit.getState


getChange(): FactoryMachineEvent

Defined in: state-machine.ts:35

Returns the last change event, including type, from, and to states.

FactoryMachineEvent

Omit.getChange


resolveExit(ev: ResolveEvent<E>): undefined | FactoryMachineEvent<FC>

Defined in: state-machine.ts:45

Determines the target (“to”) state for a new event. Returns undefined for early exit. Typically looks up transitions using machine.transitions[ev.from.key][ev.type].

ParameterType
evResolveEvent<E>

undefined | FactoryMachineEvent<FC>

Omit.resolveExit

PropertyType
statesFC["states"]
transitionsFC["transitions"]