Skip to content

Instantly share code, notes, and snippets.

@pzuraq
Created March 13, 2019 06:44
Show Gist options
  • Save pzuraq/815f7d3ab6cdcc38efc207476d704b9e to your computer and use it in GitHub Desktop.
Save pzuraq/815f7d3ab6cdcc38efc207476d704b9e to your computer and use it in GitHub Desktop.
helpers-with-injections
// 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
);
// 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