Commit 8b8b414e authored by Denys Mishunov's avatar Denys Mishunov

Vue performance plugin

The plugin to measure performance of the Vue components
using User Timing API marks and measures
parent be671e8e
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