Allow for filtering events in "once" handlers #990
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
topic: events
Currently when listening for events one may wish to filter events for certain criterion.
This is doable today by :
However the problem with explicit checks is it doesn't compose whatsoever with the
once
option that can be passed to.addEventListener
.e.g. Consider the following example with
AbortController
:Now it's possible to work around this by essentially reimplementing "once", but this seems rather redundant when the "once" option already exists.
As such I'd like to suggest that a way to filter events be added, such that failure in the filter does not prevent a "once" handler from running.
As some examples of where this would be useful:
.isTrusted
) for robustness in library code where users may be using synthetic events for triggering their own listenersI'm not sure exactly what the API shape would be, but I imagine passing a filter function in the options bag:
It's kinda redundant if you're not using
once: true
(as you can just doif (!condition) return
), in principle it could just replace theonce
e.g.once: (event) => event.key === "Escape"
, but it also seems kinda weird to overload the option (although also maybe not).The text was updated successfully, but these errors were encountered: