Commit 4212ab48 authored by Scott Stern's avatar Scott Stern Committed by Natalia Tepluhina

Unsubscribe from websocket when component unmounts

parent 0c4df6a7
...@@ -4,6 +4,7 @@ import query from '~/issuable_sidebar/queries/issue_sidebar.query.graphql'; ...@@ -4,6 +4,7 @@ import query from '~/issuable_sidebar/queries/issue_sidebar.query.graphql';
import actionCable from '~/actioncable_consumer'; import actionCable from '~/actioncable_consumer';
export default { export default {
subscription: null,
name: 'AssigneesRealtime', name: 'AssigneesRealtime',
props: { props: {
mediator: { mediator: {
...@@ -36,6 +37,9 @@ export default { ...@@ -36,6 +37,9 @@ export default {
mounted() { mounted() {
this.initActionCablePolling(); this.initActionCablePolling();
}, },
beforeDestroy() {
this.$options.subscription.unsubscribe();
},
methods: { methods: {
received(data) { received(data) {
if (data.event === 'updated') { if (data.event === 'updated') {
...@@ -43,7 +47,7 @@ export default { ...@@ -43,7 +47,7 @@ export default {
} }
}, },
initActionCablePolling() { initActionCablePolling() {
actionCable.subscriptions.create( this.$options.subscription = actionCable.subscriptions.create(
{ {
channel: 'IssuesChannel', channel: 'IssuesChannel',
project_path: this.projectPath, project_path: this.projectPath,
......
...@@ -6,7 +6,9 @@ import Mock from './mock_data'; ...@@ -6,7 +6,9 @@ import Mock from './mock_data';
import query from '~/issuable_sidebar/queries/issue_sidebar.query.graphql'; import query from '~/issuable_sidebar/queries/issue_sidebar.query.graphql';
jest.mock('@rails/actioncable', () => { jest.mock('@rails/actioncable', () => {
const mockConsumer = { subscriptions: { create: jest.fn() } }; const mockConsumer = {
subscriptions: { create: jest.fn().mockReturnValue({ unsubscribe: jest.fn() }) },
};
return { return {
createConsumer: jest.fn().mockReturnValue(mockConsumer), createConsumer: jest.fn().mockReturnValue(mockConsumer),
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment