Function

Module: @ember/object
dependentKey
String
returns
ComputedProperty
computes the largest value in the dependentKey's array

A computed property that calculates the maximum value in the dependent array. This will return -Infinity when the dependent array is empty.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { set } from '@ember/object';
import { mapBy, max } from '@ember/object/computed';

class Person {
  children = [];
  @mapBy('children', 'age') childAges;
  @max('childAges') maxChildAge;
}

let lordByron = new Person();

lordByron.maxChildAge; // -Infinity

set(lordByron, 'children', [
  {
    name: 'Augusta Ada Byron',
    age: 7
  }
]);
lordByron.maxChildAge; // 7

set(lordByron, 'children', [
  ...lordByron.children,
  {
    name: 'Allegra Byron',
    age: 5
  }, {
    name: 'Elizabeth Medora Leigh',
    age: 8
  }
]);
lordByron.maxChildAge; // 8

Classic Class Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import EmberObject, { set } from '@ember/object';
import { mapBy, max } from '@ember/object/computed';

let Person = EmberObject.extend({
  childAges: mapBy('children', 'age'),
  maxChildAge: max('childAges')
});

let lordByron = Person.create({ children: [] });

lordByron.maxChildAge; // -Infinity

set(lordByron, 'children', [
  {
    name: 'Augusta Ada Byron',
    age: 7
  }
]);
lordByron.maxChildAge; // 7

set(lordByron, 'children', [
  ...lordByron.children,
  {
    name: 'Allegra Byron',
    age: 5
  }, {
    name: 'Elizabeth Medora Leigh',
    age: 8
  }
]);
lordByron.maxChildAge; // 8

If the types of the arguments are not numbers, they will be converted to numbers and the type of the return value will always be Number. For example, the max of a list of Date objects will be the highest timestamp as a Number. This behavior is consistent with Math.max.