jbeard4 / SCION

SCXML/Statecharts in JavaScript, moved to gitlab: https://gitlab.com/scion-scxml/scion
https://scion.scxml.io
Apache License 2.0
149 stars 29 forks source link

Documentation and examples #392

Closed brucou closed 7 years ago

brucou commented 7 years ago

Frst of all congratulations for bringing life in js to Harel's statecharts formalism. I am looking for sources of documentation and examples to understand the scope of the present library.

I already looked into the SCXML specifications, which is probably the most detailed source of documentation one can find. I was however wondering if the full standard is implemented?

Also examples would be great to grok quickly the behaviour of the library, specifically when it comes to transitions between hierarchical states. If there is any such ressources (in addition to the nice one in SCION_CORE), existing or planned, please let me know.

Depending of what is already been done and tested, I would be interested in contributing ;

jbeard4 commented 7 years ago

Hi,

Thanks for your interest in SCION. I will answer your questions inline below:

I already looked into the SCXML specifications, which is probably the most detailed source of documentation one can find. I was however wondering if the full standard is implemented?

There are some fully compliant SCXML implementations, as determined by conformance to the SCXML IRP test suite [0].

SCION was first implemented in 2010, before the SCXML IRP test suite was released, so implements slightly different semantics than the one described in the Algorithm for SCXML Interpretation in the specification [1]. This wiki document provides an overview of the differences between SCION semantics and SCXML semantics [2]. In particular, SCION does not currently implement SCXML <invoke>.

The next major iteration of SCION will implement the SCXML semantics by default, providing full conformance with the IRP test suite, and deprecate the old SCION semantics. I am planning to publish this release in the near future.

Also examples would be great to grok quickly the behaviour of the library, specifically when it comes to transitions between hierarchical states. If there is any such resources (in addition to the nice one in SCION_CORE), existing or planned, please let me know.

I hope to improve the educational resources around SCXML. Please feel free to email me directly to be informed of these new developments.

Depending of what is already been done and tested, I would be interested in contributing ;

a functional API no actions performed by the state machine (only updates to an encapsulated set of variables that I would call model if the word was not so polysemic) instead the state machine emits output symbols (like state transducers) which serve to encode actions to be taken or events to be sent

You can currently achieve this through the use of state machine "snapshots". After the completion of each call to gen, call "getSnapshot" to retrieve a full copy of the state machine state. On next big-step, create a new scxml.scion.Statechart instance, and rehydrate the old state from the previous snapshot by passing the snapshot as arguments to the Statechart constructor new Statechart(model, { snapshot : snapshot }). In this approach, the SCXML model compiled by SCION and Statechart instance act as a functional state machine transducer which implements the "reaction relation" <snapshot, event> -> new_snapshot.

adding plugins dealing with asynchronicity (after I read the specs, it seems it is dealt with somewhat)

Methods scxml.scion.Statechart.prototype.gen(event) and scxml.scion.Statechart.prototype.start() have equivalent async methods scxml.scion.Statechart.prototype.genAsync(event, cb) and scxml.scion.Statechart.prototype.start(cb). These async methods call setImmediate after each microstep in order to return the thread of control back to the browser.

It looks like I need to document these methods in SCION-CORE's README.

a visualization module

I made two passes at visualization modules [3][4], and an improved visualization module is coming soon.

Please feel free to reach me with any further questions. Thanks.

[0] https://www.w3.org/Voice/2013/scxml-irp/ [1] https://www.w3.org/TR/scxml/#AlgorithmforSCXMLInterpretation [2] https://github.com/jbeard4/SCION/wiki/SCION-vs.-SCXML-Comparison [3] https://github.com/jbeard4/scxml-viz [4] https://github.com/JacobeanRnD/SCHVIZ

brucou commented 7 years ago

Thank you so much for such a detailed and quick answer. I will definitely keep in touch, and I am excited to see that you are still working on implementing this. I reviewed also https://github.com/Touffy/JSSCxml which seems to be almost fully compliant to the specs but abandonned.

A few comments:

Most importantly all the libraries I found are not functional :

If I should classify by order of importance the areas of interest when considered from the UI problem space, it would be :

1 visualization of the state-chart 2 step debugger/tracer/simulator 3 hierarchy/history/CONCURRENCY/etc. i.e. the full statechart formalism (yeah that comes third, a standard FSM already covers a nice chunk of the problem space, but it is pretty important for the non-trivial UIs of today)

Of course, I am interested in not reinventing the wheel, specially if some bright minds already have invested significant time and ressources addressing the problem space, which brought me to your library. All that to explain to you my motivation and how I came to your library.

I will keep in touch. Please let me know also if you have any comments, or if I can help you somehow.