Custom action tags

32 views
Skip to first unread message

Ricardo Morais

unread,
Apr 16, 2017, 4:19:00 AM4/16/17
to scion-dev

Hi I need some help. 


I tried using scion's executionContext to provide custom action tags to my scxml meta-model, however I  don't have a way to respond to the events. My sandbox has the function postMessage however I can't threat the event received as the image shows. How can I accomplish this.


Thanks, Ricardo Morais.

custom.png

Jacob Beard

unread,
Apr 16, 2017, 11:49:31 AM4/16/17
to scio...@googlegroups.com
Hi,

Can you please post a snippet of your code that illustrates how you are using SCION’s API?

Thank you,

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

Jacob Beard

unread,
Apr 16, 2017, 11:58:01 AM4/16/17
to scio...@googlegroups.com
Also, please see this post, which describes two techniques to expose a global variable to SCION’s execution context:


Thank you,

Jake

Ricardo Morais

unread,
Apr 16, 2017, 2:34:14 PM4/16/17
to scion-dev
Thanks for the quick response Jake, 

I want to create a new action tag, for example the <logme> tag. However I also want the logme action to be able to receive the event when it is put inside a transition. Like in my previous message the code generated does not send the event through the postMessage function (I define the postMessage in my sandbox to interpret the custom action). 

I also already read the https://groups.google.com/d/msg/scion-dev/275nXWUyjkM/nRyBDaHmDwAJ and I don't want to use the script tag.

I would like to do this in the best way possible, not in a hacky way.

Thanks again, 
Ricardo Morais.
scxml1.png
scxml1.png

Ricardo Morais

unread,
Apr 16, 2017, 2:36:06 PM4/16/17
to scion-dev
I uploaded the same image two times instead of this one, sorry.
code.png

Jacob Beard

unread,
Apr 16, 2017, 8:18:56 PM4/16/17
to scio...@googlegroups.com
Hi Ricardo,

The code you posted looks like it will successfully install the postMessage function on the global object. You can test that this is working using the <script> tag.

Regarding implementing a custom action tag, there is a specification written for this, but it is not yet implemented. I will revisit this feature soon.

Thanks,

Jake

<code.png>

Jacob Beard

unread,
Apr 16, 2017, 8:27:02 PM4/16/17
to scio...@googlegroups.com
You can track issue #336 "Formalize and expose plugin API for custom actions" here: https://github.com/jbeard4/SCION/issues/336

Ricardo Morais

unread,
Apr 16, 2017, 9:54:16 PM4/16/17
to scion-dev
Thanks for the response,

Is there a work around for this for now? I can already make my own actions, all I need is to receive the event. Is it possible for you to make a small patch like the picture shows in the scjson-to-module.js file in the 617 line?
code.png

Jacob Beard

unread,
Apr 16, 2017, 9:59:09 PM4/16/17
to scio...@googlegroups.com
Yes, the attached patch would work as a workaround. I would recommend forking the SCION repository and posting your code there.

Thank you,

Jake

Ricardo Morais

unread,
Apr 16, 2017, 10:22:35 PM4/16/17
to scion-dev
I will try that. Thank you for your time Jake.

Jacob Beard

unread,
Apr 16, 2017, 10:23:25 PM4/16/17
to scio...@googlegroups.com
You are welcome. Good luck.

Ricardo Morais

unread,
May 24, 2017, 3:10:55 PM5/24/17
to scion-dev
Hi Jake,

I have another question regarding the use of custom actions in the SCXML. Is it possible to extract the namespace of the action tag e.g. <ns:test att1=""> (extracting the 'ns')? I already have a fork of the scion library but I don't seem to be able to find how to retrieve the namespace of the tag. Do you have any idea?

Thanks,
Ricardo Morais

Jacob Beard

unread,
May 25, 2017, 9:35:40 AM5/25/17
to scio...@googlegroups.com
Hi Ricardo,

SCION compiles SCXML to an intermediate JSON format called SCJSON. SCJSON inlines “custom" namespaces (namespaces that are not SCXML or the default namespace) on the action object’s “$type” attribute using the template “{namespaceURI}localName”. This is the same technique used by the python lxml library to handle namespaces.

Previously, this technique was only applied to attributes in custom namespaces, but I have pushed a patch to apply this technique to tags as well: https://github.com/jbeard4/SCION/commit/b814d88d35842b354e84e7211e8797d692e74282

Now, for example, if you do:

    model.prepare(function(err, fnModel){
//start state machine here
    },{
      postMessage : console.log.bind(console,'custom action tag parameters:')
    });


On SCXML:

  <state id="A">
    <onentry>
      <foo:bar foo:bat="bif" belt="bin"/>
    </onentry>
  </state>
</scxml>

You will get the following output:

custom action tag parameters: { name: 'Sandbox.action',
  data:
   { '$line': 3,
     '$column': 41,
     '$type': '{http://foo.com/}bar',
     '{http://foo.com/}bat': 'bif',
     belt: 'bin' } }

You might want to use this regex from scjon-to-module.js in your code to parse out the inlined namespace: 

var stripNsPrefixRe = /^(?:{(?:[^}]*)})?(.*)$/;


You can get this change by pulling the master branch into your fork. 

Please let me know if you have any questions about this. Thank you,

Jake

Ricardo Morais

unread,
May 25, 2017, 5:24:47 PM5/25/17
to scion-dev
Hi Jake,

Thank you so much for your help, I followed your instructions and everything went well. I have another question but I think it is off-topic so I might create a new thread soon.

Best regards,
Ricardo Morais.
Reply all
Reply to author
Forward
0 new messages