/** * Created by robert on 9/15/15. */ codeq.makeStateMachine = function(def){ var currState = null; return { 'transition': function(name){ if(currState !== null) currState.exit(); currState = def[name]; currState.enter(); }, 'destroy': function(){ if(currState !== null) currState.exit(); currState = null; }, 'register': function(name,state){ def[name] = state; } } }; codeq.globalStateMachine = codeq.makeStateMachine({});