davestewart / javascript-state-machine

An expressive, feature-rich, event-driven JavaScript finite-state machine
http://statemachine.davestewart.io
343 stars 25 forks source link

Ability to capture cause of error on transition cancellation #20

Closed patternleaf closed 6 years ago

patternleaf commented 6 years ago

Howdy - I was starting to integrate state-machine into a project but it seems to be lacking a feature I wanted: at simplest, it's the ability to capture and propagate the cause of a transition cancellation.

My actual desire is the ability to treat a call to fsm.do('action') like a promise: if the transition succeeds, do X, if the transition fails, do Y, with an argument explaining why the transition failed. I think I could probably emulate this with an argument passable to fsm.cancel(error) that is then propagated to the cancel transition event. (I'd also appreciate a system-level cancel event to hook into.)

Anyway I'll probably just implement my own (far simpler) state machine but this project seems to have a lot of care behind it so thought you might appreciate the idea. No worries if it is not a use case you are interested in supporting. Thanks!

davestewart commented 6 years ago

Hey, so sorry I've only just seen this!

I haven't looked at this project for ages.

Did you solve the problem?

patternleaf commented 6 years ago

Hey thanks for commenting. I wound up building my own state machine. :) Feel free to close the issue.

davestewart commented 6 years ago

It's a fun challenge isn't it! I have lots of ideas for v2. If I ever get the time :P