zfsm
zfsm is a simple finite state 🔀 machine 🤖 TBD. Transition of zfsm can only be synchronous now, but asynchronous transition will be support in future, relax 😜 ~
Usage
jsdocs
/** * Finite state machine, whose state can be any type that is supported by lodash.isEqual method. * @param * @param * @param * @param */
Example
API
- allStates(): return all possible states.
- hasState(name): check whether state exist of configured fsm.
Code Snippet
; const fsm = initState: 'solid' transitions: event: 'melt' from: 'solid' to: 'liquid' event: 'freeze' from: 'liquid' to: 'solid' event: 'vaporize' from: 'liquid' to: 'gas' event: 'condense' from: 'gas' to: 'liquid' actions: { console; console; } { console; console; } { console; } { console; } { console; } ; console; console; console;fsm;console;fsm;console;fsm;console;fsm;console;fsm;console;fsm;console; console;
Output
'solid' 'liquid' 'gas' has state true solidbefore meltedargs: 'melt' 'solid' 'solid' 'liquid' after meltedargs: 'melt' 'liquid' 'solid' 'liquid' liquidafter froze solidbefore meltedargs: 'melt' 'solid' 'solid' 'liquid' after meltedargs: 'melt' 'liquid' 'solid' 'liquid' liquidbefore vaporized gasafter condensed liquidafter froze solid 'solid' 'liquid' 'gas'