-
Notifications
You must be signed in to change notification settings - Fork 292
Description
A thought —
Often I find I use d3-selection for checking the existence of a single element, which is a bit of a rough edge:
- You have to call
.size()
even if the selection is the result ofd3.select
(and thus size will always be either 1 or 0) - An empty selection is still truthy
This means you have to explicitly remember to call .size()
when existence checking, which sort of is counterintuitive to how selections work via the DOM.
I know the idiom is to act as if selections exist even if they're empty (so data can be bound to them eventually), but if selections were proper iterators there could be a .length
property which would make the object falsy if the selection were empty.
Turning selections into proper iterators would also make it possible to use the spread operator on selections and use all the standard array prototype methods (even if it means spreading the selection into an empty array like is frequently done with NodeList
objects).
Admittedly I have no idea how feasible or backwards compatible this idea is. 😅