Ember.computed.or()

or (dependentKey) Ember.ComputedPropertypublic

Defined in packages/ember-runtime/lib/computed/computed_macros.js:464

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

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

let tomster = Hamster.create();

tomster.get('readyForRain'); // undefined
tomster.set('hasUmbrella', true);
tomster.get('readyForRain'); // true
tomster.set('hasJacket', 'Yes');
tomster.get('readyForRain'); // 'Yes'
tomster.set('hasSunscreen', 'Check');
tomster.get('readyForBeach'); // 'Check'

Parameters:

dependentKey String

Returns:

Ember.ComputedProperty
computed property which performs a logical `or` on the values of all the original values for properties.
doc_EmberJs
2016-11-30 16:51:19
Comments
Leave a Comment

Please login to continue.