The observable array, object, Map, or Set to check.
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)
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
proxiedobject 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 calledisEmptywill be automatically scheduled for re-evaluation.