From d89f76ce9b94a20a15ac6fbee43eee75a8229f46 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Wed, 2 Nov 2016 00:17:09 +0200 Subject: [PATCH] Batch DOM updates for better performance --- src/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 6cb0f56..4c7837c 100644 --- a/src/index.js +++ b/src/index.js @@ -15,10 +15,21 @@ export default function VueMeta (Vue) { // bind the $meta method to this component instance Vue.prototype.$meta = $meta - // watch for client side updates + // store an id to keep track of DOM updates + let requestId = null + + // watch for client side component updates Vue.mixin({ mounted () { - updateClientMetaInfo(getMetaInfo(this.$root)) + // batch potential DOM updates to prevent extraneous re-rendering + window.cancelAnimationFrame(requestId) + + requestId = window.requestAnimationFrame(() => { + requestId = null + + // update the meta info + updateClientMetaInfo(getMetaInfo(this.$root)) + }) } }) }