2017-12-15 21:39:18 +00:00
|
|
|
import { computed } from '@ember/object';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
// An Ember.Computed property for summating all properties from a
|
|
|
|
// set of objects.
|
|
|
|
//
|
|
|
|
// ex. list: [ { foo: 1 }, { foo: 3 } ]
|
|
|
|
// sum: sumAggregationProperty('list', 'foo') // 4
|
|
|
|
export default function sumAggregationProperty(listKey, propKey) {
|
|
|
|
return computed(`${listKey}.@each.${propKey}`, function() {
|
2017-12-15 21:39:18 +00:00
|
|
|
return this.get(listKey)
|
|
|
|
.mapBy(propKey)
|
|
|
|
.reduce((sum, count) => sum + count, 0);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
}
|