discourse/app/assets/javascripts/ember-addons/ember-computed-decorators.j...

66 lines
2.4 KiB
Plaintext
Raw Normal View History

2018-06-15 11:03:24 -04:00
import handleDescriptor from "./utils/handle-descriptor";
import isDescriptor from "./utils/is-descriptor";
import extractValue from "./utils/extract-value";
2015-08-11 17:34:02 -04:00
export default function computedDecorator(...params) {
// determine if user called as @computed('blah', 'blah') or @computed
if (isDescriptor(params[params.length - 1])) {
return handleDescriptor(...arguments);
} else {
return function(/* target, key, desc */) {
return handleDescriptor(...arguments, params);
};
}
}
export function readOnly(target, name, desc) {
return {
2018-06-15 11:03:24 -04:00
writable: false,
enumerable: desc.enumerable,
2015-08-11 17:34:02 -04:00
configurable: desc.configurable,
2018-06-15 11:03:24 -04:00
initializer: function() {
2015-08-11 17:34:02 -04:00
var value = extractValue(desc);
return value.readOnly();
}
};
}
2018-06-15 11:03:24 -04:00
import decoratorAlias from "./decorator-alias";
2015-08-11 17:34:02 -04:00
2018-06-15 11:03:24 -04:00
export var on = decoratorAlias(Ember.on, "Can not `on` without event names");
export var observes = decoratorAlias(
Ember.observer,
"Can not `observe` without property names"
);
2015-08-11 17:34:02 -04:00
2018-06-15 11:03:24 -04:00
import macroAlias from "./macro-alias";
2015-08-11 17:34:02 -04:00
export var alias = macroAlias(Ember.computed.alias);
export var and = macroAlias(Ember.computed.and);
export var bool = macroAlias(Ember.computed.bool);
export var collect = macroAlias(Ember.computed.collect);
export var empty = macroAlias(Ember.computed.empty);
export var equal = macroAlias(Ember.computed.equal);
export var filter = macroAlias(Ember.computed.filter);
export var filterBy = macroAlias(Ember.computed.filterBy);
export var gt = macroAlias(Ember.computed.gt);
export var gte = macroAlias(Ember.computed.gte);
export var lt = macroAlias(Ember.computed.lt);
export var lte = macroAlias(Ember.computed.lte);
export var map = macroAlias(Ember.computed.map);
export var mapBy = macroAlias(Ember.computed.mapBy);
export var match = macroAlias(Ember.computed.match);
export var max = macroAlias(Ember.computed.max);
export var min = macroAlias(Ember.computed.min);
export var none = macroAlias(Ember.computed.none);
export var not = macroAlias(Ember.computed.not);
export var notEmpty = macroAlias(Ember.computed.notEmpty);
export var oneWay = macroAlias(Ember.computed.oneWay);
export var or = macroAlias(Ember.computed.or);
export var reads = macroAlias(Ember.computed.reads);
export var setDiff = macroAlias(Ember.computed.setDiff);
export var sort = macroAlias(Ember.computed.sort);
export var sum = macroAlias(Ember.computed.sum);
export var union = macroAlias(Ember.computed.union);
export var uniq = macroAlias(Ember.computed.uniq);