Commit 9d8f800f authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'ss/unsubscribe-action-cable' into 'master'

Unsubscribe from websocket when component unmounts

See merge request gitlab-org/gitlab!31039
parents de034bfd 4212ab48
...@@ -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