github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/utils/properties/sum-aggregation.js (about)

     1  import Ember from 'ember';
     2  
     3  const { computed } = Ember;
     4  
     5  // An Ember.Computed property for summating all properties from a
     6  // set of objects.
     7  //
     8  // ex. list: [ { foo: 1 }, { foo: 3 } ]
     9  //     sum: sumAggregationProperty('list', 'foo') // 4
    10  export default function sumAggregationProperty(listKey, propKey) {
    11    return computed(`${listKey}.@each.${propKey}`, function() {
    12      return this.get(listKey).mapBy(propKey).reduce((sum, count) => sum + count, 0);
    13    });
    14  }