Skip to content

Instantly share code, notes, and snippets.

@tdreyno
Created August 1, 2012 20:00
Show Gist options
  • Save tdreyno/3230185 to your computer and use it in GitHub Desktop.
Save tdreyno/3230185 to your computer and use it in GitHub Desktop.
Ember per-controller State Machine
App = Em.Application.create();
App.MyController = Em.Controller.extend({
States: Em.StateManager.extend({
errorOnUnhandledEvent: false, // true by default
enableLogging: false, // Will get noisy with a bunch of instances.
start: Em.State.extend({
enter: function(states) {
console.log("hello!", states.get('controller'));
},
loaded: function(states) {
// Sweet, move on
}
})
}),
init: function() {
this._super();
this.set('states', this.get('States').create({
controller: this
}));
// Do some setup
this.sendToState('loaded');
},
sendToState: function() {
var states = this.get('states');
return states.send.apply(states, arguments);
}
})
App.ready = function() {
App.set('myController', App.MyController.create());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment