The FSM's states. The first one is the starting state (see startsAt).
An alias for on.
Optionalcontext: unknownAdds states. The first state added becomes the current state; the last one becomes the
state that addTransition starts from when no from state is given.
Adds a transition from the last state added (see addState) to to, and returns a
function that runs it.
Adds a transition from the last state added (see addState) to to, run by trigger.
Adds a transition from from to to, run by trigger.
Removes every state, transition, and listener. Useful for cleaning up memory.
Whether the current state is state. Constraints that call this are updated when the state changes.
Removes every listener for callback that was added with on.
Calls callback when the FSM enters a state or runs a transition. spec can be:
'*': any state'state1': a state named state1 (or a comma-separated list: 'state1, state2')'state1 -> state2': right after state1 transitions to state2'state1 >- state2': right before state1 transitions to state2'state1 <-> state2': right after any transition between state1 and state2'state1 >-< state2': right before any transition between state1 and state2'state1 <- state2': right after state2 transitions to state1'state1 -< state2': right before state2 transitions to state1'state1 -> *': any transition from state1'* -> state2': any transition to state2Optionalcontext: unknown
The this for callback (default: the global object)
Note: the preferred way to create an FSM is with
cjs.fsm(...stateNames).A finite-state machine, to track the state of an interface or component.
Example