mirror of https://github.com/vuejs/vue.git
improve updateDirectives performance
This commit is contained in:
parent
25f8c50d95
commit
4f82c6abde
|
@ -12,13 +12,13 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDirectives (
|
function updateDirectives (oldVnode: VNodeWithData, vnode: VNodeWithData) {
|
||||||
oldVnode: VNodeWithData,
|
if (oldVnode.data.directives || vnode.data.directives) {
|
||||||
vnode: VNodeWithData
|
_update(oldVnode, vnode)
|
||||||
) {
|
|
||||||
if (!oldVnode.data.directives && !vnode.data.directives) {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _update (oldVnode, vnode) {
|
||||||
const isCreate = oldVnode === emptyNode
|
const isCreate = oldVnode === emptyNode
|
||||||
const oldDirs = normalizeDirectives(oldVnode.data.directives, oldVnode.context)
|
const oldDirs = normalizeDirectives(oldVnode.data.directives, oldVnode.context)
|
||||||
const newDirs = normalizeDirectives(vnode.data.directives, vnode.context)
|
const newDirs = normalizeDirectives(vnode.data.directives, vnode.context)
|
||||||
|
@ -48,9 +48,9 @@ function updateDirectives (
|
||||||
|
|
||||||
if (dirsWithInsert.length) {
|
if (dirsWithInsert.length) {
|
||||||
const callInsert = () => {
|
const callInsert = () => {
|
||||||
dirsWithInsert.forEach(dir => {
|
for (let i = 0; i < dirsWithInsert.length; i++) {
|
||||||
callHook(dir, 'inserted', vnode, oldVnode)
|
callHook(dirsWithInsert[i], 'inserted', vnode, oldVnode)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
if (isCreate) {
|
if (isCreate) {
|
||||||
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert, 'dir-insert')
|
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert, 'dir-insert')
|
||||||
|
@ -61,9 +61,9 @@ function updateDirectives (
|
||||||
|
|
||||||
if (dirsWithPostpatch.length) {
|
if (dirsWithPostpatch.length) {
|
||||||
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', () => {
|
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', () => {
|
||||||
dirsWithPostpatch.forEach(dir => {
|
for (let i = 0; i < dirsWithPostpatch.length; i++) {
|
||||||
callHook(dir, 'componentUpdated', vnode, oldVnode)
|
callHook(dirsWithPostpatch[i], 'componentUpdated', vnode, oldVnode)
|
||||||
})
|
}
|
||||||
}, 'dir-postpatch')
|
}, 'dir-postpatch')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue