Function

Module: @ember/object
dependentKey
String
returns
ComputedProperty
computed property which performs a logical `or` on the values of all the original values for properties.

A computed property which performs a logical or on the original values for the provided dependent properties.

You may pass in more than two properties and even use property brace expansion. The computed property will return the first truthy value or last falsy value just like JavaScript's || operator.

Example:

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

class Hamster {
  @or('hasSunscreen', 'hasUmbrella') readyForBeach;
}

let tomster = new Hamster();

tomster.readyForRain; // undefined

set(tomster, 'hasUmbrella', true);
tomster.readyForRain; // true

set(tomster, 'hasJacket', 'Yes');
tomster.readyForRain; // 'Yes'

set(tomster, 'hasSunscreen', 'Check');
tomster.readyForBeach; // 'Check'

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

let Hamster = EmberObject.extend({
  readyForRain: or('hasJacket', 'hasUmbrella'),
  readyForBeach: or('hasSunscreen', 'hasUmbrella')
});

let tomster = Hamster.create();

tomster.readyForRain; // undefined

set(tomster, 'hasUmbrella', true);
tomster.readyForRain; // true

set(tomster, 'hasJacket', 'Yes');
tomster.readyForRain; // 'Yes'

set(tomster, 'hasSunscreen', 'Check');
tomster.readyForBeach; // 'Check'