-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed as not planned
Closed as not planned
Copy link
Labels
awaiting submitterneeds a reproduction, or clarificationneeds a reproduction, or clarification
Description
Describe the problem
when leaving the current page in a SPA, i would like to clean things up myself, using onDestroy works great for such wonders.
But if i'm finish with that listener that i have added then i would also like to remove that event listener also.
I think it's complicated to learn all new non-standard event handler that all frameworks try to re-invent... ideally i would just simply want to have a standard EventTarget instead that do support the { once, signal } options as a third argument.
being able to use abortController would help tremendously. even for fetching data that needs to be used on a particular page.
Describe the proposed solution
import { onDestroy } from 'svelte'
const ctrl = new AbortController()
const signal = ctrl.signal
signal.addEventlistener('abort', {
elm.remove()
elm = null // remove a element since we don't need it anymore
}, { once: true, signal })
something.addEventlistener('keyup', evt => {
if (evt.key === 'escape') {
ctrl.abort()
}
}, { signal })
// unless this listener isn't removed it will still keep a references to some
// variable and prevent garbage collection if the added listener can't be removed...
onDestroy(() => {
elm.remove() // Error: can't call remove() of null
}, { signal}) // <-- add support for thisImportance
would make my life easier
Metadata
Metadata
Assignees
Labels
awaiting submitterneeds a reproduction, or clarificationneeds a reproduction, or clarification