GithubHelp home page GithubHelp logo

Comments (9)

jonnermut avatar jonnermut commented on August 14, 2024

ok, caused by a missing parameter in documentStringToModel
(the doco on the front page is wrong)

from scion.

jbeard4 avatar jbeard4 commented on August 14, 2024

Thanks, I added the missing parameter to the README.

from scion.

jonnermut avatar jonnermut commented on August 14, 2024

while I've got you... I'm having a lot of trouble actually getting a parsed statechart through that method - all I can seem to get are generated states.

For instance

var scxml = require('scxml')

var xml = `<scxml 
    xmlns="http://www.w3.org/2005/07/scxml"
    version="1.0"
    profile="ecmascript"
    initial="draft">

    <state id="draft">
    </state>

    <state id="secondState">
    </state>

</scxml>`

 scxml.documentStringToModel(null, xml, function(err, model) {
    if(err) {
        throw err;
    }

    console.log(JSON.stringify(model))

    var s = new scxml.scion.Statechart(model)

    // what can I use to get at the states?

  })

prints
{"rootScripts":[],"module":{}}

And if I inspect in a debugger there doesnt seem to be any visible states in either model or s.
I had previous code from an earlier version that would pass that model in to SCXML object (now Statechart), and list the states and transitions, how do you do that in the new API?

from scion.

jbeard4 avatar jbeard4 commented on August 14, 2024

The SCION API changed from version 2 to 3. Please now do the following:

scxml.documentStringToModel(null, xml, function(err, model) {
  model.prepare(function(err, fnModel) {

    if(err) throw err;

    //instantiate the interpreter
    var sc = new scxml.scion.Statechart(fnModel);
  });
})

model.prepare re-downloads and injects script tags without re-parsing the SCXML.

I will update SCION so that it validates the fnModel argument and throws an error if it is invalid. I have created an issue to track this here: #379

from scion.

jonnermut avatar jonnermut commented on August 14, 2024

Thanks, that would have helped track it down. This was a copy and paste of previous code without closely checking the new examples.

Couple of questions, if I may;

  1. To get the states, I am using statechart_model.states.forEach and recursing through descendants.
    Is _model now private, given the underscore, and is there a better way to do this?
  2. Is there a way to relate the states and transitions back to the xml model? Eg a reference to the xml element that created the object? I'm guessing not given the compilation model.
    I guess states always have to have an id, so I can just look them up in a DOM, but transitions etc don't.
    The use case is I'm playing around with JointJS to make a drag-drop editor, where I want changes to the diagram to update the xml, and use that as the canonical source (not the json model etc).

Thinking about it, I'm probably confusing the parser/compiler/runtime parts of SCION.
What I really want for the diagram editor is to parse the xml into a normalised JS form, and then be able to manipulate the JS form and have the xml updated, either automagically, or manually through a link back to the xml dom element.
That use case doesn't look particularly practical in SCION, but it would be a shame to have to replicate the xml parsing in SCION to do this.
Can you actually add states and transitions dynamically in SCION?

  1. From experimentation, it looks like custom attributes on elements are passed straight through, which is great. Is there any support for custom elements?
    For instance, this is an example from the spec:
<scxml:transition event="email.send">
  <my:email to="data('_event')/scxml:property[@name='email']"
            cc="data('_event')/scxml:property[@name='xmlcontent']/h:headers/h:cc"
            subject="data('_event')/scxml:property[@name='xmlcontent']/h:headers/h:subject"
            content="data('_event')/scxml:property[@name='content']"/>
</scxml:transition>

And states and transitions can have any custom elements in my understanding?
The major use case for me is triggering reusable server actions, but I probably don't understand the scxml model well enough. Could possibly just use custom attributes on existing elements I guess.

from scion.

jbeard4 avatar jbeard4 commented on August 14, 2024

To get the states, I am using statechart_model.states.forEach and recursing through descendants.
Is _model now private, given the underscore, and is there a better way to do this?

Actually, just use the following code:

let scjsonModel = fnModel()

from scion.

jbeard4 avatar jbeard4 commented on August 14, 2024

Is there a way to relate the states and transitions back to the xml model? Eg a reference to the xml element that created the object? I'm guessing not given the compilation model.
I guess states always have to have an id, so I can just look them up in a DOM, but transitions etc don't.

You can use ids to map the states. Transitions can be mapped based on their parent state, and their order in the document.

from scion.

jbeard4 avatar jbeard4 commented on August 14, 2024

Can you actually add states and transitions dynamically in SCION?

You can add states and transitions dynamically to an SCJSON, but once that is used to instantiate a simulator, updating the states and transitions of the SCJSON is not supported.

from scion.

jbeard4 avatar jbeard4 commented on August 14, 2024

From experimentation, it looks like custom attributes on elements are passed straight through, which is great. Is there any support for custom elements?

This is not currently supported, but patches are welcome.

from scion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.