Function

union (propertyKey) ComputedProperty public

Module: @ember/object
import { union } from '@ember/object/computed';
propertyKey
String
returns
ComputedProperty
computes a new array with all the unique elements from one or more dependent arrays.

A computed property which returns a new array with all the unique elements from one or more dependent arrays.

Example:

import { set } from '@ember/object';
import { union } from '@ember/object/computed';

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

  @union('fruits', 'vegetables') uniqueFruits;
});

let hamster = new, Hamster(
  [
    'banana',
    'grape',
    'kale',
    'banana',
    'tomato'
  ],
  [
    'tomato',
    'carrot',
    'lettuce'
  ]
);

hamster.uniqueFruits; // ['banana', 'grape', 'kale', 'tomato', 'carrot', 'lettuce']

Classic Class Example:

import EmberObject from '@ember/object';
import { union } from '@ember/object/computed';

let Hamster = EmberObject.extend({
  uniqueFruits: union('fruits', 'vegetables')
});

let hamster = Hamster.create({
  fruits: [
    'banana',
    'grape',
    'kale',
    'banana',
    'tomato'
  ],
  vegetables: [
    'tomato',
    'carrot',
    'lettuce'
  ]
});

hamster.uniqueFruits; // ['banana', 'grape', 'kale', 'tomato', 'carrot', 'lettuce']

© 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/union