open-consul/ui-v2/app/utils/computed/factory.js
John Cowen 4761277fd0 ui: Adds 2 computed utilities, a factory and a purify (#5079)
1. The factory is taken from the ember source, but makes it more
reusable
2. Purify converts conventional ember `computed` into a pure version

This commit only adds new files that could be used further down the line
2019-05-01 18:22:00 +00:00

19 lines
695 B
JavaScript

/**
* Gives you factory function to create a specified type of ComputedProperty
* Largely taken from https://github.com/emberjs/ember.js/blob/v2.18.2/packages/ember-metal/lib/computed.js#L529
* but configurable from the outside (IoC) so its reuseable
*
* @param {Class} ComputedProperty - ComputedProperty to use for the factory
* @returns {function} - Ember-like `computed` function (see https://www.emberjs.com/api/ember/2.18/classes/ComputedProperty)
*/
export default function(ComputedProperty) {
return function() {
const args = [...arguments];
const cp = new ComputedProperty(args.pop());
if (args.length > 0) {
cp.property(...args);
}
return cp;
};
}