jakesgordon / javascript-state-machine

A javascript finite state machine library
MIT License
8.69k stars 964 forks source link

Throw an exception when a transition is cancelled. #182

Open ghost opened 5 years ago

ghost commented 5 years ago

Good day!

In my current project, I realized my code would benefit a lot by the possibility of throwing an exception and catching it when a transition is cancelled (because in my case the transition is cancelled if some particular conditions are not met).

I've modified my fork of javascript-state-machine to include a new handler called "onCancelledTransition" that by default returns false (as expected) when a transition is cancelled, but it allows a custom implementation of onCancelledTransition handler where you can throw an error whenever one of a set of particular lifecycle events returns false (the same as onInvalidTransition and onPendingTransition).

Does the project is interested in my addition (cancelledTransition)? I could made a PR if so.