Commit 1a2d7717 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'dmishunov/vue-performance-plugin' into 'master'

Vue performance plugin

See merge request gitlab-org/gitlab!47030
parents b379a7cb 8b8b414e
const ComponentPerformancePlugin = {
install(Vue, options) {
Vue.mixin({
beforeCreate() {
/** Make sure the component you want to measure has `name` option defined
* and it matches the one you pass as the plugin option. Example:
*
* my_component.vue:
*
* ```
* export default {
* name: 'MyComponent'
* ...
* }
* ```
*
* index.js (where you initialize your Vue app containing <my-component>):
*
* ```
* Vue.use(PerformancePlugin, {
* components: [
* 'MyComponent',
* ]
* });
* ```
*/
const componentName = this.$options.name;
if (options?.components?.indexOf(componentName) !== -1) {
const tagName = `<${componentName}>`;
if (!performance.getEntriesByName(`${tagName}-start`).length) {
performance.mark(`${tagName}-start`);
}
}
},
mounted() {
const componentName = this.$options.name;
if (options?.components?.indexOf(componentName) !== -1) {
this.$nextTick(() => {
window.requestAnimationFrame(() => {
const tagName = `<${componentName}>`;
if (!performance.getEntriesByName(`${tagName}-end`).length) {
performance.mark(`${tagName}-end`);
performance.measure(`${tagName}`, `${tagName}-start`);
}
});
});
}
},
});
},
};
export default ComponentPerformancePlugin;
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