The sub plugin is used to create a state within a state machine (the parent machine) which itself behaves like a complete state machine (the states sub machine). This is easily done by using the sub property and assigning it to either a State Machine Generator Function or a State Machine Factory.

When a sub plug-in state is entered, its sub machine is immediately spawned.


prop subrequired

The sub property defines an object with properties that control how the state should use the plug-in.


prop sub.factoryrequired

Used to set the sub machine definition, either a State Machine Generator Function of a State Machine Factory object.


prop sub.smArgsoptional

The sub.smArgs property is used to defined the arguments that are passed to the factory defined in sub.factory. The property can either be a static array, or a function returning an array. If the function syntax is used, it is called using the current Transition Arguments as its arguments.

If the property is missing then the current Transition Arguments are used.


prop sub.importsoptional

If the sub machine is defined using a State Machine Generator Function the this property is used to set the imports object passed into the State Machine Factory constructor function.

If undefined then the imports object from the parent machine is used.


prop sub.optionsoptional

If the sub machine is defined using a State Machine Generator Function the this property is used to set the options object passed into the State Machine Factory constructor function.

If undefined then the options object from the parent machine is used.


event 'sub.exit'

An event called 'spawn.exit' is generated and injected into the current state when/if the sub machine reaches the @exit state. The events arguments are set to the current Transition Arguments.


event 'sub.error'

An event called 'spawn.error' is generated and injected into the current state when/if the sub machine reaches the @error state.. The events arguments are set to the current Transition Arguments.


Example

See