Create a state machine with initial state, description and options
Machine description
Options for machine (defaults to {debug:false}
)
Returns timestamp when state was last changed.
See also elapsed
Returns milliseconds elapsed since last state change.
See also changedAt
Returns true if state machine is in its final state
Gets or sets state. Throws an error if an invalid transition is attempted.
Use isValid()
to check validity without changing.
If newState
is the same as current state, the request is ignored silently.
Return a list of all defined states
Return a list of possible states from current state.
If list is empty, no states are possible. Otherwise lists possible states, including 'null' for terminal
Adds event listener.
Events
Event name
Event handler
Protected
fireFire event
Type of event
Arguments for event
Returns true if newState
is valid transition from current state.
Use validateTransition if you want an explanation for the false results.
Moves to the next state if possible. If multiple states are possible, it will use the first. If machine is finalised, no error is thrown and null is returned.
Returns new state, or null if machine is finalised
Remove event listener
Resets machine to initial state
A state machine that fires events when state changes.