mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 08:30:33 +03:00
Batch DOM updates for better performance
This commit is contained in:
+13
-2
@@ -15,10 +15,21 @@ export default function VueMeta (Vue) {
|
|||||||
// bind the $meta method to this component instance
|
// bind the $meta method to this component instance
|
||||||
Vue.prototype.$meta = $meta
|
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({
|
Vue.mixin({
|
||||||
mounted () {
|
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))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user