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
This commit is contained in:
Phil Hughes 2018-09-13 12:52:24 +01:00
parent 8287f3477f
commit a77a26eade
No known key found for this signature in database
GPG key ID: 32245528C52E0F9F
4 changed files with 10 additions and 9 deletions

View file

@ -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

View file

@ -1,7 +1,4 @@
import {
Vue,
mrWidgetOptions,
} from './dependencies';
import { Vue, mrWidgetOptions } from './dependencies';
import Translate from '../vue_shared/translate';
Vue.use(Translate);

View file

@ -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 = {

View file

@ -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');
});
});
});