Skip to content

Commit

Permalink
Merge pull request #68 from Alhada06/main
Browse files Browse the repository at this point in the history
fix: Remove particleInit event listening when a component is unmounted
  • Loading branch information
matteobruni authored Mar 6, 2024
2 parents 8150718 + c90d66f commit 8ca5ebb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions components/vue3/src/components/vue-particles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ const emit = defineEmits<{
(e: "particlesLoaded", container?: Container): void;
}>();
addEventListener("particlesInit", (e: Event) => {
const initEventHandler = (e: Event) => {
const evt = e as CustomEvent<Engine>;
engine = evt.detail;
loadParticles();
});
};
addEventListener("particlesInit", initEventHandler);
const loadParticles = async () => {
if (!engine) {
Expand Down Expand Up @@ -57,9 +58,9 @@ onUnmounted(() => {
if (!container) {
return;
}
container.destroy();
container = undefined;
removeEventListener("particlesInit", initEventHandler);
});
watch(
Expand Down

0 comments on commit 8ca5ebb

Please sign in to comment.