-
Notifications
You must be signed in to change notification settings - Fork 28
nodejs api
This document is meant to be a reference. For detailed examples of how to use SCION with node.js, see the following resources:
- https://github.com/jbeard4/SCION#useinnode.js
- https://github.com/jbeard4/SCION/tree/master/src/demo/nodejs
- https://github.com/jbeard4/SCION/tree/master/src/demo/node-repl
- https://github.com/jbeard4/SCION/tree/master/src/demo/node-web-repl
This is a JavaScript object which gets initialized from an SCXML document. The conversion process is described as follows:
- Convert SCXML to JsonML.
- Annotate JsonML document so that it is more suitable for interpretration.
- Resolve cross-references in annotated JsonML so that they are JavaScript object references.
To summarize:
SCXML → scxml-json → annotated-scxml-json → model
The options object has the following optional properties:
The optional send callback is used to allow the environment to provide platform-specific implementations of send, which facilitates external communication and implementation of the SCXML <send> element. If the send callback is not specified, SCION will use its own default, internal implementation of <send>, which supports sending events to itself with delays, but does not support communication with other statechart instances.
The send callback has the following parameters:
-
event :
- name : String
- data : anything
- origin? : String
- target? : String
-
options?
- sendid? : String
- delay? : Number, milliseconds
The optional send callback is used to allow the environment to provide platform-specific implementations of SCXML's <cancel> element. It accepts a sendid as a parameter. See the SCXML specification for more details on <cancel>.
The environment may set the original property in order to allow the SCXML instance to identify itself when using <send>. If the origin is set, the SCXML instance will attach it to the event passed to send().
method start() : Set<String>
This causes the SCXML intepreter instance to perform its initial step. It must be called before gen can be used. Returns a Set<String> of state ids.
method gen(event) : Set<String>
This causes the SCXML interpreter instance to process an event, which is passed in as an argument. Returns a Set<String> of state ids.
The event parameter is of the form:
- name : String
- data? : anything
- origin? : String
Event provides a simple constructor for creating events that may be passed into gen. Its use is optional. Any JavaScript object that has a "name" property will be properly handled as an event by gen.
Returns an Event object of the form:
- name : String
- data? : anything
This is used in the toolchain to convert SCXML to a JavaScript object that can be passed to the NodeInterpreter constructor.
This is used in the toolchain to convert SCXML to a JavaScript object that can be passed to the NodeInterpreter constructor.
An object encoding an unordered set of objects of type T:
Adds an object of type T to set.
Removes an object of type T to set.
Computes the set union of the current set and the given set, and returns the current set. Note that this updates the current set in-place.
Computes the set difference of the current set and the given set, and returns the current set. Note that this updates the current set in-place.
Returns true if the current set contains x.
Returns an Array representation of the current Set.
Returns true if the current set is empty.
Returns true if the current set is equal to the given set.
Returns a string representation of the current set.