Closed phoet closed 7 years ago
While it can be useful for testing purposes, I'm generally against the idea of a general purpose reset
method because it won't fire the full transition event lifecycle and has the potential to leave the FSM (or the resources it manages) in an inconsistent state.
In the v3 branch (releasing to npm shortly) you can make a reset
transition that respects the full lifecycle using a wildcard from
and dynamic to
transition:
init: 'none',
transitions: [
{ name: 'reset', from: '*', to: function() { return 'none' }
...
]
Note also, while not recommended, you can access the underlying original configuration if desired:
init: 'none',
transitions: [
{ name: 'reset', from: '*', to: function() { return this._fsm.config.init.state; }
...
]
i would like to add two small features to the library to make my life a bit easier when testing.
a) expose the
initial
configuration option (or the config as a whole) b) make it possible to callreset()
on a state-machine and bring it back to zero instead of having to initialize a new instancewhat do you think?