A simple Javascript state machine.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
spec
.gitignore
README.md
state_machine.js

README.md

This is a simple state machine. Using it looks something like this:

var DummyClass = function() {};
var dummyInstance = new DummyClass();

dummyInstance.stateMachine = new StateMachine();

dummyInstance.stateMachine.states = {
  StateOne: {
    enter: function() {
      // do stuff when entering this state
    },
    exit: function() {
      // do stuff when exiting a state
    }
  },
  StateTwo: {} // don't do anything when entering or exiting
}

dummyInstance.stateMachine.changeState('StateTwo');