fix: Use bus.$off to remove listeners on destroy (#3478)

This commit is contained in:
Pranav Raj S
2021-11-29 21:15:36 -08:00
committed by GitHub
parent 86dfdfb9ab
commit 0899f62912
8 changed files with 44 additions and 24 deletions

View File

@@ -11,6 +11,7 @@
<script>
import Sidebar from '../../components/layout/Sidebar';
import CommandBar from './commands/commandbar.vue';
import { BUS_EVENTS } from 'shared/constants/busEvents';
export default {
components: {
@@ -50,11 +51,10 @@ export default {
this.$store.dispatch('setCurrentAccountId', this.$route.params.accountId);
window.addEventListener('resize', this.handleResize);
this.handleResize();
bus.$on('sidemenu_icon_click', () => {
this.isSidebarOpen = !this.isSidebarOpen;
});
bus.$on(BUS_EVENTS.TOGGLE_SIDEMENU, this.toggleSidebar);
},
beforeDestroy() {
bus.$off(BUS_EVENTS.TOGGLE_SIDEMENU, this.toggleSidebar);
window.removeEventListener('resize', this.handleResize);
},
methods: {
@@ -65,6 +65,9 @@ export default {
this.isOnDesktop = false;
}
},
toggleSidebar() {
this.isSidebarOpen = !this.isSidebarOpen;
},
},
};
</script>

View File

@@ -23,6 +23,7 @@ import ChatList from '../../../components/ChatList';
import ConversationBox from '../../../components/widgets/conversation/ConversationBox';
import PopOverSearch from './search/PopOverSearch';
import uiSettingsMixin from 'dashboard/mixins/uiSettings';
import { BUS_EVENTS } from 'shared/constants/busEvents';
export default {
components: {
@@ -108,7 +109,7 @@ export default {
return;
}
this.$store.dispatch('setActiveChat', chat).then(() => {
bus.$emit('scrollToMessage');
bus.$emit(BUS_EVENTS.SCROLL_TO_MESSAGE);
});
} else {
this.$store.dispatch('clearSelectedState');