Function

Module: @ember/object

Available since v1.4.0

dependentKey
String
returns
ComputedProperty
computes the sum of all values in the dependentKey's array

A computed property that returns the sum of the values in the dependent array.

Example:

1
2
3
4
5
6
7
8
9
10
import { sum } from '@ember/object/computed';

class Invoice {
  lineItems = [1.00, 2.50, 9.99];
  @sum('lineItems') total;
}

let invoice = new Invoice();

invoice.total; // 13.49

Classic Class Example:

1
2
3
4
5
6
7
8
9
10
11
12
import EmberObject from '@ember/object';
import { sum } from '@ember/object/computed';

let Invoice = EmberObject.extend({
  lineItems: [1.00, 2.50, 9.99],

  total: sum('lineItems')
})

let invoice = Invoice.create();

invoice.total; // 13.49