State Machine GF: State Machine Object contract
A SMGF is used by the factory to produce a new state machine, and hence it must inform it of the structure of the machine. This is done by the SMGF supplying a state machine object. To support differing styles this can be done in a number of ways:
The recommended way is for the SMGF to return an entire object representing the state machine.
function smgf1 (fire) { return { startState: "Init", states: { "Init": { ... }, ... }, defaults: { ... } } ; }Within the state machine
thisrefers to an object which can be used to append state machine properties to. The SMGF should then not return a value.function smgf2 (fire) { this.startState: "Init"; this.states: { "Init": { ... }, ... }; this.defaults: { ... }; }thiscan be used to append properties to, and if the SMGF returns astringvalue then this is used to set thestartStateproperty.function smgf2 (fire) { this.states: { "Init": { ... }, ... }; this.defaults: { ... }; return "Init"; }
prop startState
String. The initial state the machine should enter once started.
prop states
Object. An object containing State Behaviour Objects, the key for each object represents that state's name.
prop defaults
Object. A State Behaviour Object whereby the properties are copied into every state within the states object if the property is not set within the target state. The actions sub-object is handled specially, in that its members are merged, whereas all other copies are shallow.