jakesgordon/javascript-state-machine — Issue #13: onleavestate should also be able to cancel an event
Author: oxplot
Created: 2011-12-29 23:31:17+00:00
State: open

In fact, I can think of more use cases where the departing state doesn't let the event to complete because of some unfinished business, as opposed to the actual event itself. Right now, onbeforeevent is the only callback from which returning false would result in cancellation of the event. I propose the same functionality in onleavestate.

Currently, returning false from onleavestate triggers an async transition. This could be changed to a different value (e.g. "async" string). It's only after we have left the old state that it no longer makes sense to cancel the event. Up until then, both callbacks should have this ability.

Here's a use case:
* SM is in "modified" state and a "close" event is fired (or any other event). The onleave callback for "modified" state will only let the transition go through if it manages to save the changes.