Function
and (dependentKey) ComputedProperty public
Module: | @ember/object |
---|
Defined in packages/@ember/object/lib/computed/computed_macros.js:792
import { and } from '@ember/object/computed';
- dependentKey
- String
- returns
- ComputedProperty
- computed property which performs a logical `and` on the values of all the original values for properties.
A computed property that performs a logical and
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 falsy value or last truthy value just like JavaScript's &&
operator.
Example:
import { set } from '@ember/object'; import { and } from '@ember/object/computed'; class Hamster { @and('hasTent', 'hasBackpack') readyForCamp; @and('hasWalkingStick', 'hasBackpack') readyForHike; } let tomster = new Hamster(); tomster.readyForCamp; // false set(tomster, 'hasTent', true); tomster.readyForCamp; // false set(tomster, 'hasBackpack', true); tomster.readyForCamp; // true set(tomster, 'hasBackpack', 'Yes'); tomster.readyForCamp; // 'Yes' set(tomster, 'hasWalkingStick', null); tomster.readyForHike; // null
Classic Class Example:
import EmberObject, { set } from '@ember/object'; import { and } from '@ember/object/computed'; let Hamster = EmberObject.extend({ readyForCamp: and('hasTent', 'hasBackpack'), readyForHike: and('hasWalkingStick', 'hasBackpack') }); let tomster = Hamster.create(); tomster.readyForCamp; // false set(tomster, 'hasTent', true); tomster.readyForCamp; // false set(tomster, 'hasBackpack', true); tomster.readyForCamp; // true set(tomster, 'hasBackpack', 'Yes'); tomster.readyForCamp; // 'Yes' set(tomster, 'hasWalkingStick', null); tomster.readyForHike; // null
© 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/and