未验证 提交 a77a26ea 编写于 作者: P 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
上级 8287f347
......@@ -10,6 +10,7 @@ import service from '../services/notes_service';
import loadAwardsHandler from '../../awards_handler';
import sidebarTimeTrackingEventHub from '../../sidebar/event_hub';
import { isInViewport, scrollToElement } from '../../lib/utils/common_utils';
import mrWidgetEventHub from '../../vue_merge_request_widget/event_hub';
let eTagPoll;
......@@ -340,7 +341,7 @@ export const fetchDiscussionDiffLines = ({ commit }, discussion) =>
});
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
......
import {
Vue,
mrWidgetOptions,
} from './dependencies';
import { Vue, mrWidgetOptions } from './dependencies';
import Translate from '../vue_shared/translate';
Vue.use(Translate);
......
......@@ -107,10 +107,14 @@ export default {
created() {
this.initPolling();
this.bindEventHubListeners();
eventHub.$on('mr.discussion.updated', this.checkStatus);
},
mounted() {
this.handleMounted();
},
beforeDestroy() {
eventHub.$off('mr.discussion.updated', this.checkStatus);
},
methods: {
createService(store) {
const endpoints = {
......
......@@ -3,6 +3,7 @@ import _ from 'underscore';
import { headersInterceptor } from 'spec/helpers/vue_resource_helper';
import * as actions from '~/notes/stores/actions';
import createStore from '~/notes/stores';
import mrWidgetEventHub from '~/vue_merge_request_widget/event_hub';
import testAction from '../../helpers/vuex_action_helper';
import { resetStore } from '../helpers';
import {
......@@ -501,13 +502,11 @@ describe('Actions Notes Store', () => {
describe('updateMergeRequestWidget', () => {
it('calls mrWidget checkStatus', () => {
gl.mrWidget = {
checkStatus: jasmine.createSpy('checkStatus'),
};
spyOn(mrWidgetEventHub, '$emit');
actions.updateMergeRequestWidget();
expect(gl.mrWidget.checkStatus).toHaveBeenCalled();
expect(mrWidgetEventHub.$emit).toHaveBeenCalledWith('mr.discussion.updated');
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册