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:
- createMachine to create a FactoryMachine instance.
Extends
Section titled “Extends”Omit
<StateMachine
<FactoryMachineEvent
<FC
>>,"send"
>
Type Parameters
Section titled “Type Parameters”Type Parameter | Default type |
---|---|
FC extends FactoryMachineContext <any > | FactoryMachineContext |
Methods
Section titled “Methods”transition()
Section titled “transition()”transition(
change
:FactoryMachineEvent
):void
Defined in: event-lifecycle.ts:28
Triggers the transition lifecycle, handling all steps for processing a change event.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
change | FactoryMachineEvent |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.transition
guard()
Section titled “guard()”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.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”Omit.guard
handle()
Section titled “handle()”handle(
ev
:FactoryMachineEvent
):undefined
|FactoryMachineEvent
<FC
>
Defined in: event-lifecycle.ts:36
Processes the event. May abort the transition if returns undefined.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”undefined
| FactoryMachineEvent
<FC
>
Inherited from
Section titled “Inherited from”Omit.handle
before()
Section titled “before()”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.)
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”undefined
| FactoryMachineEvent
<FC
>
Inherited from
Section titled “Inherited from”Omit.before
update()
Section titled “update()”update(
ev
:FactoryMachineEvent
):void
Defined in: event-lifecycle.ts:45
Applies the state update.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.update
effect()
Section titled “effect()”effect(
ev
:FactoryMachineEvent
):void
Defined in: event-lifecycle.ts:49
Runs side effects for the transition. By default, calls leave
and enter
hooks.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.effect
leave()
Section titled “leave()”leave(
ev
:FactoryMachineEvent
):void
Defined in: event-lifecycle.ts:53
Called when leaving the previous state.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.leave
enter()
Section titled “enter()”enter(
ev
:FactoryMachineEvent
):void
Defined in: event-lifecycle.ts:57
Called when entering the new state.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.enter
notify()
Section titled “notify()”notify(
ev
:FactoryMachineEvent
):void
Defined in: event-lifecycle.ts:61
Notifies subscribers of the change.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.notify
after()
Section titled “after()”after(
ev
:FactoryMachineEvent
):void
Defined in: event-lifecycle.ts:65
Final hook after transition completes. (Represents afterTransition, not state entry/exit.)
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | FactoryMachineEvent |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.after
send()
Section titled “send()”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 Parameters
Section titled “Type Parameters”Type Parameter |
---|
T extends string |
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
type | T | The event type to send |
…params | ExtractEventParams <FC , T > | The parameters for the event, typed based on the event type |
Returns
Section titled “Returns”void
getState()
Section titled “getState()”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).
Returns
Section titled “Returns”FactoryMachineEvent
<FC
>["to"
] | FactoryMachineEvent
<FC
>["from"
]
Inherited from
Section titled “Inherited from”Omit.getState
getChange()
Section titled “getChange()”getChange():
FactoryMachineEvent
Defined in: state-machine.ts:35
Returns the last change event, including type, from, and to states.
Returns
Section titled “Returns”FactoryMachineEvent
Inherited from
Section titled “Inherited from”Omit.getChange
resolveExit()
Section titled “resolveExit()”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]
.
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
ev | ResolveEvent <E > |
Returns
Section titled “Returns”undefined
| FactoryMachineEvent
<FC
>
Inherited from
Section titled “Inherited from”Omit.resolveExit
Properties
Section titled “Properties”Property | Type |
---|---|
states | FC ["states" ] |
transitions | FC ["transitions" ] |