Function
intersect (propertyKey) ComputedProperty public
Module: | @ember/object |
---|
Defined in packages/@ember/object/lib/computed/reduce_computed_macros.js:1001
import { intersect } from '@ember/object/computed';
- propertyKey
- String
- returns
- ComputedProperty
- computes a new array with all the duplicated elements from the dependent arrays
A computed property which returns a new array with all the elements two or more dependent arrays have in common.
Example:
import { set } from '@ember/object'; import { intersect } from '@ember/object/computed'; class FriendGroups { constructor(adaFriends, charlesFriends) { set(this, 'adaFriends', adaFriends); set(this, 'charlesFriends', charlesFriends); } @intersect('adaFriends', 'charlesFriends') friendsInCommon; } let groups = new FriendGroups( ['Charles Babbage', 'John Hobhouse', 'William King', 'Mary Somerville'], ['William King', 'Mary Somerville', 'Ada Lovelace', 'George Peacock'] ); groups.friendsInCommon; // ['William King', 'Mary Somerville']
Classic Class Example:
import EmberObject from '@ember/object'; import { intersect } from '@ember/object/computed'; let FriendGroups = EmberObject.extend({ friendsInCommon: intersect('adaFriends', 'charlesFriends') }); let groups = FriendGroups.create({ adaFriends: ['Charles Babbage', 'John Hobhouse', 'William King', 'Mary Somerville'], charlesFriends: ['William King', 'Mary Somerville', 'Ada Lovelace', 'George Peacock'] }); groups.friendsInCommon; // ['William King', 'Mary Somerville']
© 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/intersect