The work plug-in is used to allow a state to execute a synchronous function (the work function) asynchronously.

The work function is called using the current Transition Arguments as soon as the state machine enters the work plug-in state. The event/actions mechanism is used to transfer control back to the state when the work function returns. The name of the events injected into the state machine are set by the returned value of the work function, which should either be a String, or an Array with a String as its first element.


prop workrequired

The work property is used to define how the state should use the plug-in.

If only the work function needs to be specified then an work property should be a synchronous function definition (see work.fn).

If additional context information is necessary, e.g. the specification of the arguments for the work function, then the work property should be an object containing the property fn and optionally the fnArgs and ctx properties, all described below.


prop work.fnrequired

Used to set the synchronous function (the work function) to be executed asynchronously. The work function should return a String, or an Array with a String as its first agrument. The String will be used to name the event injected into the state machine by adding a postfix to 'work.' (e.g. a return value of '"done'" will generate an event called 'work.done'). Any subsequent argument returned in an Array will be used to set new values for the Transition Arguments.


prop work.fnArgsoptional

The work.fnArgs property is used to defined the arguments that are passed to the work function defined in work.fn. 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 as the work functions arguments.


prop work.ctxoptional

The work.ctx (context) property is used to determine the value of this inside the function. If work.ctx is null or undefined, this will be the global object. If work.ctx is a function, this will be its return value, Object(work.ctx()). Otherwise if work.ctx is an Object or primitive value, this will be Object(work.ctx).


event 'work.*'

An event called 'work.*' is generated and injected into the current state when the work function returns. The wildcard * is set to the returned value if a String or otherwise the first argument of the returned value if an Array (which should be a String).

If an Array is returned the subsequent elements (after the initial element which is used to name the event) are used as the event arguments, otherwise the event has none.


Example

See