Each state within the machine is defined within a State Behaviour Object (SBO) which takes a number of specific properties to define the state. The possible key values defined here represent those understood by the ignite.js core, but it should be noted that these are added to by plug-ins.


prop guard

A guard condition can be defined for a state to specify a condition that has to be true for the state to be entered. The guard can be synchronous or asynchronous. If the test can be done synchronously (e.g. checking the length of an array), then the guard should be specified as a simple function. This function should return a false value (or have no explicit return) if the test passes and the state should be entered. Alternatively, it should return a state name to divert to, either as a string, or as the first value within an array containing new transition arguments if these also need to be altered.

An asynchronous guard is specified as a sub State Machine Behaviour object, but with the difference that any actions that return a false value will cause the state to be entered.

There is more on guards here.

parameters

[arg1 [, arg2 [, ...]]]
varargs: The current [transition arguments].

returns

null, undefined, etc.
Enter state and wait for events
$string
Re-direct to specified state.
$array
Re-direct to state specified in first element, set transition arguments to subsequent elements.

prop setTA

Function. A function to alter the current transition arguments. Called after the guard function, but before entry functions.

parameters

[arg1 [, arg2 [, ...]]]
varargs: The transition arguments set when the state was entered.

returns

$array
A new set of transition arguments.

prop entry

Function. This function is called as the state machine is entering the state, and is often used to initiate some asynchronous process. If the entry function returns a false value (e.g. null, undefined or has no explicit return) then the state is said to have entered and is therefore waiting for an event to be injected. If the entry function returns a string value, then the state machine does not proceed any further into entering this state and gets diverted to the state corresponding to the string value. The transition arguments are not affected.

If the entry function returns an array value, then the state machine does not proceed any further into entering this state and gets diverted to the state corresponding to the string value which is the first element of the array. The transition arguments are set to the subsequent array elements.

If an entry function never returns a false value then the state will never wait within the state and hence such states are said to be transient.

parameters

[arg1 [, arg2 [, ...]]]
varargs: The current [transition arguments].

returns

null, undefined, etc.
Enter state and wait for events
$string
Transition to specified state.
$array
Transition to state specified in first element, set transition arguments to subsequent elements.

prop exit

Function. This function is used as a state is exited when changing to another state (or the current state is re-entered with the alias '@self'). The return value of the exit function has no effect.


prop actions

Object. An object within which the keys represent event names, or patterns to match with event names, and the values dictate the action to take when an event is received that matches the pattern.

The values can take a string value, an array or a function (which returns a string or an array).

This is described further here.


prop defer

Array. A shortcut to deferring a number of events with '@defer' in the actions object, instead a list of event names can be given as a defer property.


prop ignore

Array. A shortcut to ignoring a number of events with '@ignore' within the actions object, instead a list of event names can be given as a ignore property.


prop error

Array. A shortcut to specifying that a number of events should exit the state machine with an error (by setting the event name key to '@error' in the actions object) by setting the error property to a list of event names.

// These state objects are equivalent
// Option 1
"A_State": {
  entry: ...,
  defer: ['eventA', 'eventB'],
  ignore: ['eventC', 'eventD', 'eventE'],
  error: ['eventF', 'eventG'],
  actions: {
    ...
  }
}
// Option 2
"A_State": {
  entry: ...,
  actions: {
    'eventA': '@defer',
    'eventB': '@defer',
    'eventC': '@ignore',
    'eventD': '@ignore',
    'eventE': '@ignore',
    'eventF': '@error',
    'eventG': '@error',
  }
}

prop nextState

String. Specifies a value to use for the '@next' state alias.