Emitted when the state machine enters a state.
Emitted when the state machine leaves a state.
Emitted when the state machine executes a transition. The srcState and the dstState values represent the deepest source state and destination state respectively.
Emitted when the state machine executes a transition. The srcStates and the dstStates arrays contain the full state hierarchy, from top to the bottom.
Add an event to state machine.
the event to be added.
Add a new state to the state machine. If the subStateMachine parameter is present, it means the given state has subStates, represented by the given subStateMachine.
The state to be added.
Optional
subStateMachine: StateMachine<StateT, EventT>The subStateMachine associated with the given state.
Add a transition to the state machine.
The event which triggers the transition.
The source state of the transition. It must be either a state of the current state machine or a sub state, only if dstState is a state of the current state machine.
The destination state of the transition. It must be either a state of the current state machine or a sub state, only if srcState is a state of the current machine.
Checks if the current state is the one passed, if not, throws an error.
The state to check the current state.
Reset to the initial state the stateMachine and its subStateMachines, if they don't have history.
The event which triggered the reset.
Set the initial state and the history of the state machine.
the initial state.
rather the state machine has history or not. Defaults to false.
Triggers the given event.
The triggered event.
State machine class.
This class manages state machines and their events emits.
Emitted events
The state machines emit 4 event types:
History
The history configuration gives the possibility to specify if leaving a state will reset the sub state machine to the initial state or not. If the history flag is set to true, the sub state machine is not reset and when the parent state machine enters the state back, the old state of the sub state machine is restored. The history configuration can be optionally set through the setInitialState call. Default value is 'false'.
Transition between current SM state and subSM states
Transitions between current state machine and states of the subStateMachines can be defined, only if the source state or the destination state represent states of the state machine for which the transition is defined.
Usage:
The following state machine will be created in typescript:
hide empty description
[] -> NotInitialized
Initialized -left-> NotInitialized : shutdown
NotInitialized -right-> Initialized[H] : init
state Initialized {
[] --> NotListening
NotListening -right-> Listening : startListen
Listening -left-> NotListening : stopListen
}