Function
bool (dependentKey) ComputedProperty public
Module:
@ember/object
Defined in packages/@ember/object/lib/computed/computed_macros.js:321
import { bool } from '@ember/object/computed'; |
- dependentKey
- String
- returns
- ComputedProperty
- computed property which converts to boolean the original value for property
A computed property that converts the provided dependent property into a boolean value.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import { set } from '@ember/object'; import { bool } from '@ember/object/computed'; class Hamster { @bool('numBananas') hasBananas } let hamster = new Hamster(); hamster.hasBananas; // false set(hamster, 'numBananas', 0); hamster.hasBananas; // false set(hamster, 'numBananas', 1); hamster.hasBananas; // true set(hamster, 'numBananas', null); hamster.hasBananas; // false |
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 { bool } from '@ember/object/computed'; let Hamster = EmberObject.extend({ hasBananas: bool('numBananas') }); let hamster = Hamster.create(); hamster.hasBananas; // false set(hamster, 'numBananas', 0); hamster.hasBananas; // false set(hamster, 'numBananas', 1); hamster.hasBananas; // true set(hamster, 'numBananas', null); hamster.hasBananas; // false |