Created
April 9, 2020 04:30
-
-
Save lukemelia/b2e5c3ad7cc7dcb7e65b5bea08e82e4b to your computer and use it in GitHub Desktop.
Example of defining your own decorator macro using https://pzuraq.github.io/macro-decorators
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
import { reads }, macro from 'macro-decorators'; | |
/* Usage: | |
* | |
* import { hasEnabledFeature } from 'yapp-ember-kit/macro-decorators'; | |
* | |
* @reads('yappService.model') yapp; | |
* @hasEnabledFeature('teleportation') canTeleport; | |
*/ | |
export function hasEnabledFeature(featureName, yappProperty='yapp') { | |
return macro({ | |
get() { | |
let yapp = this[yappProperty]; | |
return yapp && yapp.hasEnabledFeature(featureName); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment