In node.js, install SCION 2.0 via npm:
npm install scxml
In the browser, add the following script tags to your web page:
Note that SCION 2.0 assumes the presence of jQuery to handle cross-browser XMLHTTPRequest, however an alternative Ajax library could instead be used. This is set up in the following way:
//perform this setup once, before SCION is usedscxmlextplatformModuleplatformajax =//call your preferred Ajax library here to do HTTP GET//if dataType is 'xml', the Ajax response must be parsed as DOM//call your preferred Ajax library here to do HTTP POST;
Support is currently being added for Rhino.
Here is an example of a typical usage:
In node, you can also use
var model = require'./path/to/foo.scxml';//etc...
Note that this will only work if the SCXML
<script> tags contain local filesystem paths, and not references to 'http:' URIs. The reason for this is that node's
require() is a synchronous API, but requesting resources across a network must be done asynchronously.
SCION allows you to instantiate SCXML interpreters from SCXML "model" objects, which are SCXML documents that have been processed for easier interpretation. These methods allow you to create an SCXML model from an XML DOM document, document string, or url/path to document.
The SCXML constructor creates an interpreter instance from a model object.
statechart.start starts the SCXML interpreter.
statechart.start should only be called once, and should be called before
statechart.gen is called for the first time.
Returns a "basic configuration", which is an Array of strings representing the ids all of the basic states the interpreter is in after the call to
An SCXML interpreter takes SCXML events as input, where an SCXML event is an object with "name" and "data" properties. These can be passed to method
gen as two positional arguments, or as a single object.
statechart.gen returns a "basic configuration", which is an Array of strings representing the ids all of the basic states the interpreter is in after the call to
var statechart = Statechartmodelvar data = foo:1;var configuration = statechartgen"eventName"data;//the following call is equivalentvar configuration = statechartgenname:"eventName"data:foo:1;
An SCXML interpreter has three forms of output:
<send>element to send SCXML events to web services. Right now, the
<send>tag is not supported by SCION out of the box. This should be better supported by next release.
Registers a callback to receive notification of state changes, as described above.
onTransition callback is optional - if the property is not present, it will be ignored.
Furthermore, for the
onTransition callback, argument
targetStateIds will be
null for targetless transitions, rather than, e.g. an empty array.