Function
collect (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/@ember/object/lib/computed/reduce_computed_macros.js:1188
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:
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:
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']
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fobject%2Fcomputed/collect