StateMachineJS
Implementation of State Machine Pattern in JavaScript.
Get Started
-
Define states in host object
var app = // host object for state machinestates: // states definitionname: 'STATE_A' // state nameentry: 'stateAEntry' // state entry functionexit: 'stateAExit' // state exit functiontransitions: // transitions definitiontrigger: 'event1' // transition triggerdest: 'STATE_B' // transition destinationaction: 'action1' // transition action functionguard: 'guard1' // transition guard functionname: 'STATE_B' // minimal state definition// host object is used as the context (`this`) of all state functions{// this function will be called when entering STATE_A}{// this function will be called when leaving STATE_A}{// this function will be called when "event1" transition is taking place}{// this function returns `false` to prevent "event1" transition from// happening}; -
Initialize host object
StateMachine; -
Check current state
app; // => 'STATE_A', app is now in the first state -
Trigger state transition
app -
Check current state again
app; // => 'STATE_B', app is now in the STATE_B state
API Document
TODO