github.com/manicqin/nomad@v0.9.5/ui/app/utils/properties/sum-aggregation.js (about)

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