Function
empty (dependentKey) ComputedProperty public
Module:
@ember/object
Defined in packages/@ember/object/lib/computed/computed_macros.js:63
Available since v1.6.0
import { empty } from '@ember/object/computed'; |
- dependentKey
- String
- returns
- ComputedProperty
- computed property which returns true if the value of the dependent property is null, an empty string, empty array, or empty function and false if the underlying value is not empty.
A computed property macro that returns true if the value of the dependent property is null, an empty string, empty array, or empty function.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import { set } from '@ember/object'; import { empty } from '@ember/object/computed'; class ToDoList { constructor(todos) { set(this, 'todos', todos); } isDone; } let todoList = new ToDoList( ['Unit Test', 'Documentation', 'Release'] ); todoList.isDone; // false set(todoList, 'todos', []); todoList.isDone; // true |
Classic Class Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import EmberObject, { set } from '@ember/object'; import { empty } from '@ember/object/computed'; let ToDoList = EmberObject.extend({ isDone: empty('todos') }); let todoList = ToDoList.create({ todos: ['Unit Test', 'Documentation', 'Release'] }); todoList.isDone; // false set(todoList, 'todos', []); todoList.isDone; // true |