Created
November 7, 2012 19:01
-
-
Save audionerd/4033647 to your computer and use it in GitHub Desktop.
Stativus example (pseudo-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cat = new Cat() | |
| var statechart = Stativus.createStatechart() | |
| statechart.addState("meowing", { | |
| enterState: function(){ | |
| cat.startMeowing() | |
| }, | |
| exitState: function(){ | |
| cat.stopMeowing() | |
| }, | |
| nextBehavior: function(){ | |
| this.goToState('sleeping'); | |
| } | |
| }); | |
| statechart.addState("sleeping", { | |
| enterState: function(){ | |
| cat.goToSleep() | |
| }, | |
| exitState: function(){ | |
| cat.wakeUp() | |
| }, | |
| nextBehavior: function(){ | |
| this.goToState('meowing'); | |
| } | |
| }); | |
| // start meowing | |
| statechart.initStates('meowing'); | |
| // ... and later, call nextBehavior to switch states | |
| statechart.sendEvent('nextBehavior'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment