2018-06-15 11:03:24 -04:00
|
|
|
import extractValue from "./utils/extract-value";
|
2015-08-11 17:34:02 -04:00
|
|
|
|
|
|
|
export default function decoratorAlias(fn, errorMessage) {
|
|
|
|
return function(...params) {
|
2019-11-07 16:38:28 -05:00
|
|
|
// determine if user called as @discourseComputed('blah', 'blah') or @discourseComputed
|
2015-08-11 17:34:02 -04:00
|
|
|
if (params.length === 0) {
|
|
|
|
throw new Error(errorMessage);
|
|
|
|
} else {
|
|
|
|
return function(target, key, desc) {
|
|
|
|
return {
|
|
|
|
enumerable: desc.enumerable,
|
|
|
|
configurable: desc.configurable,
|
|
|
|
writable: desc.writable,
|
|
|
|
initializer: function() {
|
|
|
|
var value = extractValue(desc);
|
|
|
|
return fn.apply(null, params.concat(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|