Created
March 13, 2019 06:44
-
-
Save pzuraq/815f7d3ab6cdcc38efc207476d704b9e to your computer and use it in GitHub Desktop.
helpers-with-injections
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
// Helper that has the router service injected as the first parameter. Benefits: | |
// | |
// 1. Still stateless, all state is owned by the service, so no possibility of bugs due to statefulness of the instance | |
// 2. Much easier to write, less boilerplate | |
// 3. Subjectively easier to read | |
// | |
function routeActive(router, [routeName]) { | |
return router.isActive(routeName); | |
} | |
export default helper( | |
{ services: ['router'] }, | |
routeActive | |
); |
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
// Possible future API with decorators | |
@helper | |
export default routeActive( | |
@service router, | |
[routeName] | |
) { | |
return router.isActive(routeName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment