Function
collect (dependentKey) ComputedProperty public
Module:
@ember/object
Defined in packages/@ember/object/lib/computed/reduce_computed_macros.js:1193
import { collect } from '@ember/object/computed'; |
- dependentKey
- String
- returns
- ComputedProperty
- computed property which maps values of all passed in properties to an array.
A computed property that returns the array of values for the provided dependent properties.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import { set } from '@ember/object'; import { collect } from '@ember/object/computed'; class Hamster { @collect('hat', 'shirt') clothes; } let hamster = new Hamster(); hamster.clothes; // [null, null] set(hamster, 'hat', 'Camp Hat'); set(hamster, 'shirt', 'Camp Shirt'); hamster.clothes; // ['Camp Hat', 'Camp Shirt'] |
Classic Class Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import EmberObject, { set } from '@ember/object'; import { collect } from '@ember/object/computed'; let Hamster = EmberObject.extend({ clothes: collect('hat', 'shirt') }); let hamster = Hamster.create(); hamster.clothes; // [null, null] set(hamster, 'hat', 'Camp Hat'); set(hamster, 'shirt', 'Camp Shirt'); hamster.clothes; // ['Camp Hat', 'Camp Shirt'] |