Skip to content

Instantly share code, notes, and snippets.

@audionerd
Created November 7, 2012 19:01
Show Gist options
  • Select an option

  • Save audionerd/4033647 to your computer and use it in GitHub Desktop.

Select an option

Save audionerd/4033647 to your computer and use it in GitHub Desktop.
Stativus example (pseudo-code)
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