scxml.js - is it still supported?

49 views
Skip to first unread message

Jeff Chimene

unread,
Dec 18, 2016, 2:35:25 PM12/18/16
to scion-dev
Is scxml.js still supported?

If so, are global variables referenced in <script> tags available in internet explorer?

for example, document.getElementById("salesPage").style.display = "block";
fails, as document.getElementById("salesPage") is null.

It looks like global variables are available in chrome and firefox.

any suggestions would be appreciated.

Jacob Beard

unread,
Dec 18, 2016, 3:43:21 PM12/18/16
to scio...@googlegroups.com
Hi Jeff,

On Dec 18, 2016, at 2:35 PM, Jeff Chimene <jchi...@gmail.com> wrote:

Is scxml.js still supported?

Yes. scxml.js became the 2.0 branch of SCION. SCION is still supported.
This is not directly supported

SCION initializes SCXML code inside of a sandbox. In node.js it uses the vm module for this, and in the browser it executes the SCXML code inside of an iframe. Code executed inside of an iframe has a different global object than the global variables initialized on the page into which SCION is loaded.

For that reason, you need to expose global variables to the SCXML scripting context, and there are two ways to do this:

You could initialize an API object, and pass that into the state machine as an event, for example, outside of the state machine run:

//define your API, which references global variables
let api = {
setBlockStyle : function(){
document.getElementById("salesPage").style.display = "block";
}
};

//pass it into the state machine
sc.gen(‘init’, api).

And the SCXML would have the form:

<scxml>
<datamodel>
<data id=“api”/>
</datamodel>

<state id=“initial_default">
<transition target=“initialized” event=“init”>
<assign location=“api” expr=“_event.data”/>
</transition>
</state>
<state id=“initialized”>
<!-- then you can call the API -->
<transition event=“foo”>
<script>
api.setBlockStyle();
</script>
</transition>
</state>
</scxml>


The alternative approach to this would be to use a new API introduced in SCION 3.0:

model.prepare(function(err, fnModel) {}, executionContext, hostContext)

This API lets you pass in an object as the executionContext. In node.js the executionContext is a v8 vm sandbox object. This gives you an alternative approach to exposing global variables to your state machine code.

In the browser, I believe you can pass in a regular object as the executionContext, as the browser does not have an explicit concept of a sandbox object. Please feel free to give this a try, and let me know if you have any trouble with it.

Thanks,

Jake



--
You received this message because you are subscribed to the Google Groups "scion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scion-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeffrey Chimene

unread,
Dec 18, 2016, 6:02:05 PM12/18/16
to scio...@googlegroups.com
Thanks, Jake, that worked.

To be complete, I'm using this as follows:

In the HTML page that prepares the state machine:

api = { jQuery : function() { return jQuery; }};

and the state's script is

<script>
    $ = api.jQuery();
    $("#salesPage").show();
<script>

the <state id="initial_state"> and <data id="api"> are as you indicated
Reply all
Reply to author
Forward
0 new messages