From 74f8da7fbcf77f74dad62e290ba397ebc19a5d93 Mon Sep 17 00:00:00 2001 From: Daniel Thompson-Yvetot <35242872+nothingismagick@users.noreply.github.com> Date: Tue, 7 May 2019 11:31:21 +0200 Subject: [PATCH] feat(cleanup) destroy vue listeners pt. 2 Closes #468. This commit cleans up custom event listeners by destroying them when the component no longer exists. --- src/main/zapHomeFiles/hud/panel.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/zapHomeFiles/hud/panel.js b/src/main/zapHomeFiles/hud/panel.js index bf98fd67f..4ed0963b9 100644 --- a/src/main/zapHomeFiles/hud/panel.js +++ b/src/main/zapHomeFiles/hud/panel.js @@ -120,6 +120,9 @@ Vue.component('hud-button', { } } }) + }, + beforeDestroy () { + eventBus.$off('updateButton') } }); @@ -190,8 +193,11 @@ Vue.component('hud-buttons', { eventBus.$on('removeButton', data => { self.tools = self.tools.filter(tool => tool.name !== data.name); }) + }, + beforeDestroy () { + eventBus.$off('addButton') + eventBus.$off('removeButton') } - }); document.addEventListener("DOMContentLoaded", () => { @@ -210,7 +216,7 @@ document.addEventListener("DOMContentLoaded", () => { data: { } - }); + }); }); function doesContextApply(toolContext) { @@ -225,7 +231,7 @@ function doesContextApply(toolContext) { navigator.serviceWorker.addEventListener("message", event => { var message = event.data; let tool; - + switch(message.action) { case "broadcastUpdate": tool = message.tool;