Closed jonnermut closed 7 years ago
ok, caused by a missing parameter in documentStringToModel (the doco on the front page is wrong)
Thanks, I added the missing parameter to the README.
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?
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: https://github.com/jbeard4/SCION/issues/379
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;
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?
<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.
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()
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.
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 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.
Seems that the scxml.documentStringToModel func is somehow broken?
This code in node (latest):
gives the error:
It does the same thing in the browser. Using pathToModel seems to work ok.