1.0.1 • Published 3 years ago
@jswork/next-fsm v1.0.1
next-fsm
A finite state machine for next.
installation
npm install -S @jswork/next-fsm
apis
api | params | description |
---|---|---|
init | - | initial state |
transitions | - | states list |
onTransition | - | When transition change |
transition | - | Change state directly |
usage
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');
resources
license
Code released under the MIT license.