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
I think exposing an AbortSignal as part of the ElementInternals would be an ergonomic simplification around reversing the operations in a connectedCallback() (e.g. by passing a signal to eventlisteners or fetch calls).
What problem are you trying to solve?
It's quite common to want to bind to event listeners on global objects, or parent objects to take advantages of delegate event listening. Doing so requires tearing down those listeners, which can be a little cumbersome.
What solutions exist today?
AbortController makes this easier but it can still involve a fair amount of boilerplate; here's the minimum viable code to register an event listener with appropriate AbortController code:
I'd like to introduce an AbortSignal intrinsic to the CE lifecycle, one that gets automatically set up just beforeconnectedCallback() and gets aborted just before (or maybe just after?) disconnectedCallback(). In doing so, the above code could become something like:
Whenever an element gets connected, it would abort and dispose of its associated connectedSignal, and create a new one. Calling this.#internals.connectedSignal() would return the current associated connectedSignal. When an element disconnects from the DOM, it would abort its associated signal.
This would alleviate much of the work around creating and managing an AbortController just to abstract the work of connectedCallback/disconnectedCallback.
Anything else?
No response
The text was updated successfully, but these errors were encountered:
See whatwg/dom#1296
I think exposing an
AbortSignal
as part of the ElementInternals would be an ergonomic simplification around reversing the operations in aconnectedCallback()
(e.g. by passing asignal
to eventlisteners or fetch calls).The text was updated successfully, but these errors were encountered: