Skip to content

Instantly share code, notes, and snippets.

@rlivsey
Created October 11, 2017 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlivsey/00d120f1d1ff27c89769324f5d29cb68 to your computer and use it in GitHub Desktop.
Save rlivsey/00d120f1d1ff27c89769324f5d29cb68 to your computer and use it in GitHub Desktop.
// services/router.js
import Router from '@ember/services/router' // or wherever it lives
import Evented from '@ember/evented'
export default Router.extend(Evented);
// your helper
export default Helper.extend({
router: service(),
init() {
this._super(...arguments);
this._fn = () => this.recompute();
this.get('router').on('didTransition', this._fn);
},
willDestroy() {
this.get('router').off('didTransition', this._fn);
},
compute() {
// magic here
}
});
// application/route.js
export default Route.extend({
router: service(),
actions: {
didTransition() {
this.get('router').trigger('didTransition');
return true;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment