Created
September 3, 2015 14:24
-
-
Save xcambar/7d2d116519c68eb54868 to your computer and use it in GitHub Desktop.
Let the outside world know that your Ember app has successfully transitioned from a route to another
This file contains 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
/* | |
* For the sake of simplicity, | |
* Let's assume that your app is globally regostered as `MyApp` | |
*/ | |
// Prepare your app to trigger the `transitioned` event | |
MyApp.reopen(Ember.Evented); | |
MyApp.__container__.lookup('controller:application').addObserver('currentPath', function () { | |
var _path = this.get('currentPath'); | |
if (_path.indexOf('loading') !== -1) { return; } | |
if (_path.indexOf('error') !== -1) { return; } | |
Ember.run.scheduleOnce( | |
'afterRender', | |
this, | |
MyApp.trigger.bind(MyApp, 'transitioned', _path)); | |
}); | |
//Register a listener | |
MyApp.on('transitioned', function (path) { | |
console.log('Transitioned to', path); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment