Skip to content

isEmpty

isEmpty(proxied): boolean

Defined in: aberdeen.ts:1218

Reactively checks if an observable array, object, Map, or Set is empty.

This function not only returns the current emptiness state but also establishes a reactive dependency. If the emptiness state of the proxied object or array changes later (e.g., an item is added to an empty array, or the last property is deleted from an object), the scope that called isEmpty will be automatically scheduled for re-evaluation.

TargetType

The observable array, object, Map, or Set to check.

boolean

true if the array has length 0, the Map/Set has size 0, or the object has no own enumerable properties, false otherwise.

const $items = A.proxy([]);
// Reactively display a message if the items array is empty
A('div', () => {
if (A.isEmpty($items)) {
A('p i#No items yet!');
} else {
A.onEach($items, item => A('p#'+item));
}
});
// Adding an item will automatically remove the "No items yet!" message
setInterval(() => {
if (!$items.length || Math.random()>0.5) $items.push('Item');
else $items.length = 0;
}, 1000)