-
Notifications
You must be signed in to change notification settings - Fork 29
Action Tag Scripting API
This document describes features of SCION that are not part of the SCXML specification.
SCION has built-in support for the tags described as Executable Content in the SCXML specification.
The functionality provided by these tags can also be accessed programmatically via JavaScript in a <script>
tag, or in any SCXML JavaScript expression. This can be useful if, for example, you have already described your executable content in JavaScript, but wish to, for example, send an event using SCXML <send>
.
You can assign to elements in the SCXML datamodel directly using JavaScript assignment expressions. This works pretty much as you would expect, for example:
<scxml>
<datamodel>
<data id="foo" expr="1"/>
</datamodel>
<state id="a">
<onentry>
console.log(foo); //prints 1
foo = 2;
console.log(foo); //prints 2
</onentry>
</state>
</scxml>
Just use regular JavaScript if
, elseif
, else
statements.
Just use regular JavaScript functional array methods, e.g.
<scxml>
<datamodel>
<data id="foo" expr="[1,2,3]"/>
</datamodel>
<state id="a">
<onentry>
//prints 1\n2\n3\n
foo.forEach(function(n){
console.log(n);
});
</onentry>
</state>
</scxml>
this.raise(eventName : String)
this.cancel(sendid : Number)
this.send(event : Event [, options : SendOptions])
Event is an object of the form:
{
"target" : String
"name" : String
"type" : String
"data" : String
"origin" : String
}
SendOptions is an optional object of the form:
{
"delay" : Number
"sendId" : String
}
this.invoke(invokeObj : InvokeObj)
InvokeObj is an object which has the following properties:
Required property:
- id : String
Required one of:
- constructorFunction : a SCION ModelFactory
- content : an SCXML document String
- src: a string with a path to a URL of an SCXML document to execute
Optional properties:
- parentSession : a SCION Statechart instance that is the parent session. This is needed if you want to use
<send>
to communicate between parent and child sessions. - params : An object of key-value pairs of values to set in the invoked session's datamodel.
- docUrl : The url of the invoked doc. This can be useful for source map support, if you are, for example, using the
content
property described above, and want the source map to be associated with a docUrl (e.g., so you can look up with Command+O in chrome dev tools).
this.cancelInvoke(invokeId : String)
Manually cancel the invoked sessesion specified by invokeId