github.com/hernad/nomad@v1.6.112/ui/app/utils/properties/sum-aggregation.js (about)

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