Skip to content
This repository was archived by the owner on Sep 25, 2018. It is now read-only.

nodejs api

Jacob Beard edited this page Feb 8, 2012 · 3 revisions

SCION node.js API reference

This document is meant to be a reference. For detailed examples of how to use SCION with node.js, see the following resources:

package scion

class NodeInterpreter

constructor(model, options)

parameter model

This is a JavaScript object which gets initialized from an SCXML document. The conversion process is described as follows:

  1. Convert SCXML to JsonML.
  2. Annotate JsonML document so that it is more suitable for interpretration.
  3. Resolve cross-references in annotated JsonML so that they are JavaScript object references.

To summarize:

SCXML → scxml-json → annotated-scxml-json → model

parameter options

The options object has the following optional properties:

send? : function (event,options)

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
cancel? : function(sendid : String)

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>.

origin? : String

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

class Event

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.

constructor(name : String, data? : anything)

Returns an Event object of the form:

  • name : String
  • data? : anything

function annotateScxmlJson(scxmlJson)

This is used in the toolchain to convert SCXML to a JavaScript object that can be passed to the NodeInterpreter constructor.

function json2model

This is used in the toolchain to convert SCXML to a JavaScript object that can be passed to the NodeInterpreter constructor.

Set<T>

An object encoding an unordered set of objects of type T:

method add(T x)

Adds an object of type T to set.

method remove(T x)

Removes an object of type T to set.

method union(Set<T>) : Set<T>

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.

method difference(Set<T>)

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.

method contains(T x) : boolean

Returns true if the current set contains x.

method iter() : Array<T>

Returns an Array representation of the current Set.

method isEmpty() : boolean

Returns true if the current set is empty.

method equals(Set<T>) : boolean

Returns true if the current set is equal to the given set.

method toString() : String

Returns a string representation of the current set.