You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wondering if there has been any discussion around a better "built-in" solution to this sort of requirement?
// An `await`able function that resolves when page visibility changes:functionvisibilityChange(){returnnewPromise(resolve=>{document.addEventListener("visibilitychange",function(){resolve(document.visibilityState);document.removeEventListener("visibilitychange",arguments.callee);});});}// Use it like this:awaitvisibilityChange();console.log(document.visibilityState);
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:
just maybe i would apply it to a more generic util pattern to some like:
constonce=(elm,type)=newPromise(rs=>el.addEventListener('visibilitychange',rs,{once: true}))// and use it as such:constevt=awaitonce(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
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: