A finite state machine for next.
npm install -S @jswork/next-fsm
api | params | description |
---|---|---|
init | - | initial state |
transitions | - | states list |
onTransition | - | When transition change |
transition | - | Change state directly |
import NxFsm from 'next-fsm';
const fsm = new nx.Fsm({
init: false,
transitions: [
{ name: 'on', from: false, to: true },
{ name: 'off', from: true, to: false }
],
onTransition: function(inEvent) {
const { value } = inEvent.target;
times++;
console.log('current state:', value);
}
});
fsm.on();
fsm.off();
fsm.transition('on');
fsm.transition('off');
Code released under the MIT license.