Skip to content

Instantly share code, notes, and snippets.

@geoffreyd
Created February 18, 2011 05:44
Show Gist options
  • Save geoffreyd/63c790db4883498578ca to your computer and use it in GitHub Desktop.
Save geoffreyd/63c790db4883498578ca to your computer and use it in GitHub Desktop.
StateChart Observer Example Usage
rootState: Ki.State.design({
initialSubstate: 'loading',
loading: Ki.State.design({
enterState: function() {
var controller = App.ticketsController;
this._observer = this.addStatechartObserver(controller, 'status', 'statusChanged');
controller.set('content', App.store.find(App.TICKET_QUERY));
},
statusChanged: function(target, key, revision) {
if (target === App.ticketsController && key === 'status') {
if (target.get(key) === SC.Record.READY_CLEAN) this.gotoState('idle') ;
// else ignore any other status changes
}
},
exitState: function() {
this.removeStatechartObserver(App.ticketsController, 'status', this._observer) ;
this._observer = null ;
}
}),
idle:Ki.State.design({
enterState: function() {
console.log('idle');
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment