[Help]: Can (and should I) clean up embla listeners? #1247
-
SummaryFunctions like (See example below) If applicable, which variants of Embla Carousel are relevant to this question?
Additional informationWe currently have something like this (pseudo code): <script>
function onemblaInit( event ) {
const embla = event.detail;
embla.on('event', onEvent);
// Does this work? Is it needed?
() => embla.off('event', onEvent);
}
</script>
<carousel {onemblaInit} ... />CodeSandbox exampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Good question! Event handlers in Embla will persist for the full lifecycle of the carousel instance — even across Svelte packageCore package used by the Svelte packageembla-carousel/packages/embla-carousel/src/components/EmblaCarousel.ts Lines 149 to 156 in 0848932 So, you only need to manually call |
Beta Was this translation helpful? Give feedback.
Hi @roderickdecorrespondent,
Good question! Event handlers in Embla will persist for the full lifecycle of the carousel instance — even across
reInitcalls — until the carousel is explicitly destroyed. When the Svelte component is unmounted,destroy()is automatically called, and all event handlers are cleaned up at that point:Svelte package
embla-carousel/packages/embla-carousel-svelte/src/components/emblaCarouselSvelte.ts
Lines 50 to 52 in 0848932
Core package used by the Svelte package
embla-carousel/packages/embla-carousel/src/components/EmblaCarousel.ts
Lines 149 to 156 in 0848932