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';
import actionCable from '~/actioncable_consumer';
export default {
subscription: null,
name: 'AssigneesRealtime',
props: {
mediator: {
......@@ -36,6 +37,9 @@ export default {
mounted() {
this.initActionCablePolling();
},
beforeDestroy() {
this.$options.subscription.unsubscribe();
},
methods: {
received(data) {
if (data.event === 'updated') {
......@@ -43,7 +47,7 @@ export default {
}
},
initActionCablePolling() {
actionCable.subscriptions.create(
this.$options.subscription = actionCable.subscriptions.create(
{
channel: 'IssuesChannel',
project_path: this.projectPath,
......
......@@ -6,7 +6,9 @@ import Mock from './mock_data';
import query from '~/issuable_sidebar/queries/issue_sidebar.query.graphql';
jest.mock('@rails/actioncable', () => {
const mockConsumer = { subscriptions: { create: jest.fn() } };
const mockConsumer = {
subscriptions: { create: jest.fn().mockReturnValue({ unsubscribe: jest.fn() }) },
};
return {
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