-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One-time await
able event listeners
#8513
Comments
Here are some vaguely related discussions, though all existing discussion seems to revolve around loading rather than events more generally. |
whatwg/dom#1038 maybe? |
You could also do: function visibilityChange() {
return new Promise(rs => document.addEventListener('visibilitychange', rs, { once: true }))
} just maybe i would apply it to a more generic util pattern to some like: const once = (elm, type) = new Promise(rs => el.addEventListener('visibilitychange', rs, { once: true }))
// and use it as such:
const evt = await once(document, 'visibilitychange')
console.log(document.visibilityState) I don't particularly see any need for a one-time awaitable event listener. it can already be solved in user land. i think there is other more important features that gets higher priority such as those thing that can't be polyfilled |
Let's duplicate this into the DOM issue. HTML doesn't define Events. |
Wondering if there has been any discussion around a better "built-in" solution to this sort of requirement?
I find myself doing this sort of thing fairly often (for many different types of events - not just
visibilitychange
) and it feels very "clunky".The text was updated successfully, but these errors were encountered: