Function
none (dependentKey) ComputedProperty public
Module: | @ember/object |
---|
Defined in packages/@ember/object/lib/computed/computed_macros.js:196
import { none } from '@ember/object/computed';
- dependentKey
- String
- returns
- ComputedProperty
- computed property which returns true if original value for property is null or undefined.
A computed property that returns true if the value of the dependent property is null or undefined. This avoids errors from JSLint complaining about use of ==, which can be technically confusing.
import { set } from '@ember/object'; import { none } from '@ember/object/computed'; class Hamster { @none('food') isHungry; } let hamster = new Hamster(); hamster.isHungry; // true set(hamster, 'food', 'Banana'); hamster.isHungry; // false set(hamster, 'food', null); hamster.isHungry; // true
Classic Class Example:
import EmberObject, { set } from '@ember/object'; import { none } from '@ember/object/computed'; let Hamster = EmberObject.extend({ isHungry: none('food') }); let hamster = Hamster.create(); hamster.isHungry; // true set(hamster, 'food', 'Banana'); hamster.isHungry; // false set(hamster, 'food', null); hamster.isHungry; // true
© 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/none