StateMachineJS
Implementation of State Machine Pattern in JavaScript.
Get Started
-
Define states in host object
var app = {
states: [{
name: 'STATE_A'
entry: 'stateAEntry'
exit: 'stateAExit'
transitions: [{
trigger: 'event1'
dest: 'STATE_B'
action: 'action1'
guard: 'guard1'
}]
}, {
name: 'STATE_B'
}],
stateAEntry: function() {
},
stateAExit: function() {
},
action1: function() {
},
guard1: function() {
}
};
-
Initialize host object
StateMachine.init(app);
-
Check current state
app.getCurrentStateName();
-
Trigger state transition
app.handleStateTrigger('event1')
-
Check current state again
app.getCurrentStateName();
API Document
TODO