Created
August 1, 2012 20:00
-
-
Save tdreyno/3230185 to your computer and use it in GitHub Desktop.
Ember per-controller State Machine
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
| 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