Created
October 11, 2017 13:36
-
-
Save rlivsey/00d120f1d1ff27c89769324f5d29cb68 to your computer and use it in GitHub Desktop.
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
// 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