diff options
author | Aleš Smodiš <aless@guru.si> | 2015-09-21 17:45:31 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-09-21 17:45:31 +0200 |
commit | cee672f22d516ecc73f84a3dbe01328883a2a47d (patch) | |
tree | 2f977f01c4619d2e422cbc8b498218cbe9972dc4 /js/codeq/stateMachine.js | |
parent | 86b478fc57f6eb8bc1addd07d4feb95c83f6792c (diff) |
Refactoring: simplified python.js and prolog.js, removed all DOM IDs except for the top-level block #screen_prolog, made a copy of the latter into #screen_python so the two screens can now diverge.
Diffstat (limited to 'js/codeq/stateMachine.js')
-rw-r--r-- | js/codeq/stateMachine.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/js/codeq/stateMachine.js b/js/codeq/stateMachine.js index cfb27e7..dff89d5 100644 --- a/js/codeq/stateMachine.js +++ b/js/codeq/stateMachine.js @@ -6,8 +6,17 @@ codeq.makeStateMachine = function(def){ var currState = null; return { 'transition': function(name){ + var newState = def[name]; + if (!newState) { + codeq.log.error('Cannot transition to state ' + name + ': it is not defined'); + return; + } + if (newState === currState) { + codeq.log.info('Will not transition between identical states: ' + name); + return; + } if(currState !== null) currState.exit(); - currState = def[name]; + currState = newState; currState.enter.apply(currState,Array.prototype.slice.apply(arguments,[1])); }, 'destroy': function(){ @@ -15,6 +24,7 @@ codeq.makeStateMachine = function(def){ currState = null; }, 'register': function(name,state){ + if (name in def) codeq.log.error('The state ' + name + ' is already registered, overriding'); def[name] = state; } } |