Commit a77a26ea authored by Phil Hughes's avatar Phil Hughes

Use MR widget event_hub to dispatch update event

Instead of relying on a global method, we now emit an event on the MR
widget that tells it to check the status
parent 8287f347
...@@ -10,6 +10,7 @@ import service from '../services/notes_service'; ...@@ -10,6 +10,7 @@ import service from '../services/notes_service';
import loadAwardsHandler from '../../awards_handler'; import loadAwardsHandler from '../../awards_handler';
import sidebarTimeTrackingEventHub from '../../sidebar/event_hub'; import sidebarTimeTrackingEventHub from '../../sidebar/event_hub';
import { isInViewport, scrollToElement } from '../../lib/utils/common_utils'; import { isInViewport, scrollToElement } from '../../lib/utils/common_utils';
import mrWidgetEventHub from '../../vue_merge_request_widget/event_hub';
let eTagPoll; let eTagPoll;
...@@ -340,7 +341,7 @@ export const fetchDiscussionDiffLines = ({ commit }, discussion) => ...@@ -340,7 +341,7 @@ export const fetchDiscussionDiffLines = ({ commit }, discussion) =>
}); });
export const updateMergeRequestWidget = () => { export const updateMergeRequestWidget = () => {
if (gl.mrWidget) gl.mrWidget.checkStatus(); mrWidgetEventHub.$emit('mr.discussion.updated');
}; };
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
......
import { import { Vue, mrWidgetOptions } from './dependencies';
Vue,
mrWidgetOptions,
} from './dependencies';
import Translate from '../vue_shared/translate'; import Translate from '../vue_shared/translate';
Vue.use(Translate); Vue.use(Translate);
......
...@@ -107,10 +107,14 @@ export default { ...@@ -107,10 +107,14 @@ export default {
created() { created() {
this.initPolling(); this.initPolling();
this.bindEventHubListeners(); this.bindEventHubListeners();
eventHub.$on('mr.discussion.updated', this.checkStatus);
}, },
mounted() { mounted() {
this.handleMounted(); this.handleMounted();
}, },
beforeDestroy() {
eventHub.$off('mr.discussion.updated', this.checkStatus);
},
methods: { methods: {
createService(store) { createService(store) {
const endpoints = { const endpoints = {
......
...@@ -3,6 +3,7 @@ import _ from 'underscore'; ...@@ -3,6 +3,7 @@ import _ from 'underscore';
import { headersInterceptor } from 'spec/helpers/vue_resource_helper'; import { headersInterceptor } from 'spec/helpers/vue_resource_helper';
import * as actions from '~/notes/stores/actions'; import * as actions from '~/notes/stores/actions';
import createStore from '~/notes/stores'; import createStore from '~/notes/stores';
import mrWidgetEventHub from '~/vue_merge_request_widget/event_hub';
import testAction from '../../helpers/vuex_action_helper'; import testAction from '../../helpers/vuex_action_helper';
import { resetStore } from '../helpers'; import { resetStore } from '../helpers';
import { import {
...@@ -501,13 +502,11 @@ describe('Actions Notes Store', () => { ...@@ -501,13 +502,11 @@ describe('Actions Notes Store', () => {
describe('updateMergeRequestWidget', () => { describe('updateMergeRequestWidget', () => {
it('calls mrWidget checkStatus', () => { it('calls mrWidget checkStatus', () => {
gl.mrWidget = { spyOn(mrWidgetEventHub, '$emit');
checkStatus: jasmine.createSpy('checkStatus'),
};
actions.updateMergeRequestWidget(); actions.updateMergeRequestWidget();
expect(gl.mrWidget.checkStatus).toHaveBeenCalled(); expect(mrWidgetEventHub.$emit).toHaveBeenCalledWith('mr.discussion.updated');
}); });
}); });
}); });
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