Function

Module: @ember/object
setAProperty
String
setBProperty
String
returns
ComputedProperty
computes a new array with all the items from the first dependent array that are not in the second dependent array

A computed property which returns a new array with all the properties from the first dependent array that are not in the second dependent array.

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

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

  @setDiff('likes', 'fruits') wants;
}

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

hamster.wants; // ['banana']

Classic Class Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import EmberObject from '@ember/object';
import { setDiff } from '@ember/object/computed';

let Hamster = EmberObject.extend({
  wants: setDiff('likes', 'fruits')
});

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

hamster.wants; // ['banana']