Commit 746806b8 authored by Lukas Eipert's avatar Lukas Eipert

Safe guard performance bar initialization

On certain pages, where the performance bar isn't loaded, the
initialization will error out.
parent a24cb95f
...@@ -5,14 +5,15 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -5,14 +5,15 @@ import axios from '~/lib/utils/axios_utils';
import PerformanceBarService from './services/performance_bar_service'; import PerformanceBarService from './services/performance_bar_service';
import PerformanceBarStore from './stores/performance_bar_store'; import PerformanceBarStore from './stores/performance_bar_store';
const initPerformanceBar = ({ container }) => const initPerformanceBar = el => {
new Vue({ const performanceBarData = el.dataset;
el: container,
return new Vue({
el,
components: { components: {
PerformanceBarApp: () => import('./components/performance_bar_app.vue'), PerformanceBarApp: () => import('./components/performance_bar_app.vue'),
}, },
data() { data() {
const performanceBarData = document.querySelector(this.$options.el).dataset;
const store = new PerformanceBarStore(); const store = new PerformanceBarStore();
return { return {
...@@ -118,9 +119,13 @@ const initPerformanceBar = ({ container }) => ...@@ -118,9 +119,13 @@ const initPerformanceBar = ({ container }) =>
}); });
}, },
}); });
};
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
initPerformanceBar({ container: '#js-peek' }); const jsPeek = document.querySelector('#js-peek');
if (jsPeek) {
initPerformanceBar(jsPeek);
}
}); });
export default initPerformanceBar; export default initPerformanceBar;
...@@ -44,7 +44,7 @@ describe('performance bar wrapper', () => { ...@@ -44,7 +44,7 @@ describe('performance bar wrapper', () => {
{}, {},
); );
vm = performanceBar({ container: '#js-peek' }); vm = performanceBar(peekWrapper);
}); });
afterEach(() => { afterEach(() => {
......
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