Typically, the contents of the SMGF do not contain all the information needed to create a factory and successfully use a state machine as there is other information required, such as the required imports libraries. In order that such information can be kept with the SMGF, various properties can be set on it.


prop apioptional

An array of strings, where each string represents a method name that will be made available on both the Factory and any spawned state machines. Each method causes an event to be injected into the state machine (on the next tick). Any arguments to the methods are passed as the event arguments. The name of which is generated from the method name by prepending 'api.' to it,

Calls to the methods on the factory broadcast the event to all running state machines.

function exampleSMGF (fire) {
  ...
}
// Register three method names that should be created
exampleSMGF.api = [ "connect", "disconnect", "send" ];

// Create factory
var factory = ignite.Factory(exampleSMGF) ;

// Spawn a state machine
var sm = factory.spawn() ;

// Such machines have three methods created to match the names above

// This will send an 'api.connect' method with a single argument:
sm.connect("something.com") ;


// The factory also has the methods created, calling these broadcasts the
// event to all running machines:
factory.disconnect(true) ;

prop defaultsoptional

Object. The defaults object can contain a number of different properties, which are used as default values to various aspects of the machine. Typically, these can be overridden (and sometimes altered) through the Factory and State Machine APIs


prop defaults.argsoptional

Array. Used as default arguments to a state machine created and started with the Factory.launch() method.

smExample.defaults = {
  args: ["arg1", anotherArg],
  imports: { fs: require('fs'), nodeHttp: require('http') },
  options: { logLevel: 2 }
};

prop defaults.callbackoptional

Function. Used as the default callback to be registered when a state machine is created and started with the Factory.launch() method.


prop defaults.importsoptional

Object. Used as the default imports when a Factory object is created. Any imports given within the call to the constructor function will override or appended to the imports object used.


prop defaults.optionsoptional

Object. Used as the default options when a Factory object is created. Any options given within the call to the constructor function will override or append to the options object used.


prop defaults.onoptional

Object containing Functions. This object can contain functions which will be registered as listeners with a state machine spawned with the Factory.launch() method. The property names represent the event name that the listener will be registered with.


prop defaults.onceoptional

Object containing Functions. This object can contain functions which will be registered as once() listeners with a state machine spawned with the Factory.launch() method. The property names represent the event name that the listener will be registered with.

smExample.defaults = {
  args: ["arg1", anotherArg],
  imports: { fs: require('fs'), nodeHttp: require('http') },
  on: {
    change: function (sm, newState, oldState) {
      console.log("Changing to ", newState);
    }
  },
  once: {
    done: function (sm) {
      console.log("Done!");
    }
  }
};

prop runneroptional

A SMGF can also have a runner object attached to it. The possible keys within this object are identical to those give above for the default object, but they are only used when the state machine is started with the ignite helper application (in the default run mode).