Function

Module: @ember/object
dependentKey
String
additionalDependentKeys
Array
optional array of additional dependent keys
callback
Function
returns
ComputedProperty
an array mapped via the callback

Returns an array mapped via the callback

The callback method you provide should have the following signature:

  • item is the current item in the iteration.
  • index is the integer index of the current item in the iteration.
1
function mapCallback(item, index);

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
import { set } from '@ember/object';
import { map } from '@ember/object/computed';

class Hamster {
  constructor(chores) {
    set(this, 'chores', chores);
  }

  @map('chores', ['shouldUpperCase'], function(chore, index) {
    if (this.shouldUpperCase) {
      return `${chore.toUpperCase()}!`;
    } else {
      return `${chore}!`;
    }
  })
  excitingChores;
}

let hamster = new Hamster(['clean', 'write more unit tests']);

hamster.excitingChores; // ['clean!', 'write more unit tests!']

set(hamster, 'shouldUpperCase', true);
hamster.excitingChores; // ['CLEAN!', 'WRITE MORE UNIT TESTS!']