Skip to content

Commit

Permalink
improve updateDirectives performance
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 5, 2016
1 parent 25f8c50 commit 4f82c6a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/core/vdom/modules/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export default {
}
}

function updateDirectives (
oldVnode: VNodeWithData,
vnode: VNodeWithData
) {
if (!oldVnode.data.directives && !vnode.data.directives) {
return
function updateDirectives (oldVnode: VNodeWithData, vnode: VNodeWithData) {
if (oldVnode.data.directives || vnode.data.directives) {
_update(oldVnode, vnode)
}
}

function _update (oldVnode, vnode) {
const isCreate = oldVnode === emptyNode
const oldDirs = normalizeDirectives(oldVnode.data.directives, oldVnode.context)
const newDirs = normalizeDirectives(vnode.data.directives, vnode.context)
Expand Down Expand Up @@ -48,9 +48,9 @@ function updateDirectives (

if (dirsWithInsert.length) {
const callInsert = () => {
dirsWithInsert.forEach(dir => {
callHook(dir, 'inserted', vnode, oldVnode)
})
for (let i = 0; i < dirsWithInsert.length; i++) {
callHook(dirsWithInsert[i], 'inserted', vnode, oldVnode)
}
}
if (isCreate) {
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert, 'dir-insert')
Expand All @@ -61,9 +61,9 @@ function updateDirectives (

if (dirsWithPostpatch.length) {
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', () => {
dirsWithPostpatch.forEach(dir => {
callHook(dir, 'componentUpdated', vnode, oldVnode)
})
for (let i = 0; i < dirsWithPostpatch.length; i++) {
callHook(dirsWithPostpatch[i], 'componentUpdated', vnode, oldVnode)
}
}, 'dir-postpatch')
}

Expand Down

0 comments on commit 4f82c6a

Please sign in to comment.