State Machine API
constructor
The state machine constructor should be considered private, as state machines should be spawned by the Factory.
extends EventEmitter
Every state machine is also an EventEmitter. The state machine framework will emit a number of events as the machine runs, and the functions within a state machine can also emit events by calling fire.$event.
event 'call'
An event, typically used for debugging, emitted when the state machine calls a user defined function (i.e. one of the functions defined within an SMGF).
parameters
sm- Object: state machine object
fnName- String: a textual representation of the function.
event 'change'
A change event is emitted by the state machine when a state change occurs.
parameters
sm- Object: state machine object
newStateName- String: textual name of the state about to be entered.
prevStateName- String: textual name of the state that has just been left.
event 'ctor'
This is always the first event emitted by the state machine and indicates that the constructor has completed and the machine is fully defined.
parameters
sm- Object: state machine object
event 'done'
Typically used for debugging and internal control, the done event is emitted when the state machine enters one of the terminal states ('@exit' or '@enter').
parameters
sm- Object: state machine object
type- String: either
'enter'or'exit'depending on the terminal state entered. [arg3 [, arg4 [, ...]]]- varargs: Terminal transition arguments set when the state machine exited.
event 'enter'
This event is emitted when the machine leaves the initial '@enter' state, and enters the user defined start-state.
parameters
sm- Object: state machine object
event 'error'
After a state machine has entered the terminal '@error' state, the state machine will emit an error event. The arguments are the transition arguments that were set when the '@error' state was entered, unless the first transition argument equates to null, in which case the argument is set to an auto-generated error code. Typically, the user code inside the state machine should ensure that this first argument is set and provides useful information on the error encountered.
The emission of this event is placed on the event queue (with nextTick()) to ensure the state machine has cleanly exited before any listeners are invoked. If you need an event at the point of exit, see done below.
parameters
err- Error: Error encountered within machine.
[arg2 [, arg3 [, ...]]]- varargs: Other terminal transition arguments set when the state machine exited.
event 'event'
An event event is emitted when the state machine has an event injected into it.
parameters
sm- Object: state machine object
evtName- String: textual name of the event.
evtArgs- Array: list of arguments associated with event.
event 'exit'
After a state machine has entered the terminal '@exit' state, the state machine will emit an exit event. The arguments are the transition arguments that were set when the '@exit' state was entered.
The emission of this event is placed on the event queue (with nextTick()) to ensure the state machine has cleanly exited before any listeners are invoked. If you need an event at the point of exit, see done below.
parameters
[arg1 [, arg2 [, ...]]]- varargs: Terminal transition arguments set when the state machine exited.
event 'warn'
An event, typically used for debugging, emitted when the state machine has detected a situation that could be an error. Examples are when an 'unexpected' event is injected (i.e. an event is received that has no matching action defined), when the machine attempts to change to an undefined state, or when an event is received after the state it was expected in has left ('late transition event').
parameters
sm- Object: state machine object
stateName- String: the name of the current state
evtName- String: the name of the event injected (if relevant to the warning)
warning- String: the text of the warning