Created
September 18, 2019 14:48
-
-
Save chrismllr/08a0142337f868f231ee75aa1c70d2e6 to your computer and use it in GitHub Desktop.
ember @arg decorator
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
/** | |
* @description Declares a one-way read-only component property, which reads from `this.args` | |
* and falls back to default declared on the class property. | |
* @export | |
* @returns {ClassProperty} | |
*/ | |
export default function arg(target, property, descriptor) { | |
let _value; | |
if (descriptor.initializer !== null) { | |
_value = descriptor.initializer(); | |
} | |
const newDescriptor = { | |
get() { | |
if (property in this.args) { | |
return this.args[property]; | |
} | |
if (!('_value' in newDescriptor)) { | |
newDescriptor._value = _value; | |
} | |
return newDescriptor._value; | |
}, | |
enumerable: true, | |
configurable: true | |
}; | |
return newDescriptor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helps with the ambiguity of whether to reference
@aProperty
orthis.aProperty
in templates. By this standard, if your component has a javascript file, you'll usethis.
, and if it is template-only, you'll use@
Usage