2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-13 06:22:23 +03:00

Batch DOM updates for better performance

This commit is contained in:
Declan de Wet
2016-11-02 00:17:09 +02:00
parent ba81428a73
commit d89f76ce9b
+13 -2
View File
@@ -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))
})
}
})
}