- Hierarchical states: states can be configured to have an unlimited number of substates, an unlimited number of levels deep.
- Guards: an unlimited amount of callbacks can be set to guard both entry and exit of states.
- Listeners: an unlimited amount of callbacks can be executed on both entry and exit of states.
- Named transitions: switching of states happens through named transitions.
- Asynchronous transitioning: transitioning from one state to the other can be paused/resumed.
- Framework independent: doesn’t rely on any other 3rd party frameworks.
var offState = new jsfsa.State( 'off' ) .addTransition( 'ignite', 'on' ) .isInitial = true ; var onState = new jsfsa.State( 'on' ) .addTransition( 'shutdown', 'off' ) ; var fsm = new jsfsa.Automaton() .addState( offState ) .addState( onState ) .doTransition( 'ignite' ) ; console.log( fsm.getCurrentState().name );//outputs 'on'
Code and examples
For source code, a more extensive explanation and examples head on over to the github project