Comments (9)
ok, caused by a missing parameter in documentStringToModel
(the doco on the front page is wrong)
from scion.
Thanks, I added the missing parameter to the README.
from scion.
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.
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.
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;
- 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? - 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?
- 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.
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.
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.
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.
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)
- The target id parser is a URL parser, not a URI parser HOT 3
- validate the fnModel argument in SCION constructor and throw an error if it is invalid
- should reject an scxml document containing data without @id
- should reject an scxml document containing assign without @location
- should reject an scxml document containing foreach without @item
- should reject an scxml document containing foreach without @array
- should accept an scxml document containing foreach with object literal @array
- should validate param tags at parse time
- reject scxml documents with raise and no @event at parse time
- validate send *expr attributes at parse time
- Add namespace to custom action tag names
- Multiple state identifiers in initial attribute not supported HOT 2
- [README.MD] Demo links do not work
- Documentation and examples HOT 2
- improve documentation for compiling scxml HOT 10
- improve documentation concerning interface to statemachine HOT 20
- accessing application context from scxml HOT 1
- Starting state machine within running state machine HOT 17
- empty <datamodel> block throws "Unexpected token" SyntaxError HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scion.