Skip to content

Commit 4f82c6a

Browse files
committed
improve updateDirectives performance
1 parent 25f8c50 commit 4f82c6a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/core/vdom/modules/directives.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export default {
1212
}
1313
}
1414

15-
function updateDirectives (
16-
oldVnode: VNodeWithData,
17-
vnode: VNodeWithData
18-
) {
19-
if (!oldVnode.data.directives && !vnode.data.directives) {
20-
return
15+
function updateDirectives (oldVnode: VNodeWithData, vnode: VNodeWithData) {
16+
if (oldVnode.data.directives || vnode.data.directives) {
17+
_update(oldVnode, vnode)
2118
}
19+
}
20+
21+
function _update (oldVnode, vnode) {
2222
const isCreate = oldVnode === emptyNode
2323
const oldDirs = normalizeDirectives(oldVnode.data.directives, oldVnode.context)
2424
const newDirs = normalizeDirectives(vnode.data.directives, vnode.context)
@@ -48,9 +48,9 @@ function updateDirectives (
4848

4949
if (dirsWithInsert.length) {
5050
const callInsert = () => {
51-
dirsWithInsert.forEach(dir => {
52-
callHook(dir, 'inserted', vnode, oldVnode)
53-
})
51+
for (let i = 0; i < dirsWithInsert.length; i++) {
52+
callHook(dirsWithInsert[i], 'inserted', vnode, oldVnode)
53+
}
5454
}
5555
if (isCreate) {
5656
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert, 'dir-insert')
@@ -61,9 +61,9 @@ function updateDirectives (
6161

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy