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

Know if event is handled by state machine or not #357

Open mogsie opened 9 years ago

mogsie commented 9 years ago

When gen() is called, it returns the basic configuration of the state machine after processing the event. But sometimes the event is (correctly) ignored by the state machine. It is sometimes useful to detect these situations, e.g. so that DOM preventDefault() can be called in case the event is handled, and not call preventDefault() if the state machine didn't handle the event.

Imagine a situation where certain keystrokes are fed to the state machine (e.g. up, down, left, right) and that we want to prevent the default propagation of the keystroke event if and only if the state machine handled the event. I don't want to have to litter calls to e.preventDefault() events in the SCXML, as the SCXML is decoupled from the DOM itself, and introducing a dependency is unnecessary and ugly.

I was thinking that the response to gen could be null in the case where the event was not handled. It would probably break backward compatibility so it's not a feasible solution.

Is this at all interesting for other applications?