Skip to content

Commit 4a74883

Browse files
committed
improve mergeVNodeHook logic
1 parent e9bf5d1 commit 4a74883

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/core/vdom/helpers.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ export function getFirstComponentChild (children: ?Array<any>) {
6565
return children && children.filter(c => c && c.componentOptions)[0]
6666
}
6767

68-
export function mergeVNodeHook (def: Object, key: string, hook: Function) {
69-
const oldHook = def[key]
68+
export function mergeVNodeHook (def: Object, hookKey: string, hook: Function, key: string) {
69+
key = key + hookKey
70+
const injectedHash = def.__injected || (def.__injected = {})
71+
if (injectedHash[key]) return
72+
injectedHash[key] = true
73+
const oldHook = def[hookKey]
7074
if (oldHook) {
71-
const injectedHash = def.__injected || (def.__injected = {})
72-
if (!injectedHash[key]) {
73-
injectedHash[key] = true
74-
def[key] = function () {
75-
oldHook.apply(this, arguments)
76-
hook.apply(this, arguments)
77-
}
75+
def[hookKey] = function () {
76+
oldHook.apply(this, arguments)
77+
hook.apply(this, arguments)
7878
}
7979
} else {
80-
def[key] = hook
80+
def[hookKey] = hook
8181
}
8282
}
8383

src/core/vdom/modules/directives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
if (hasInsert) {
1616
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', () => {
1717
applyDirectives(oldVnode, vnode, 'inserted')
18-
})
18+
}, 'dir-insert')
1919
}
2020
},
2121
update: function updateDirectives (oldVnode: VNodeWithData, vnode: VNodeWithData) {

src/platforms/web/runtime/components/transition.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default {
119119
return placeholder(h, rawChild)
120120
}
121121

122-
child.key = child.key == null || child.isStatic
122+
const key = child.key = child.key == null || child.isStatic
123123
? `__v${child.tag + this._uid}__`
124124
: child.key
125125
const data = (child.data || (child.data = {})).transition = extractTransitionData(this)
@@ -132,7 +132,7 @@ export default {
132132
child.data.show = true
133133
}
134134

135-
if (oldChild && oldChild.data && oldChild.key !== child.key) {
135+
if (oldChild && oldChild.data && oldChild.key !== key) {
136136
// replace old child transition data with fresh one
137137
// important for dynamic transitions!
138138
const oldData = oldChild.data.transition = extend({}, data)
@@ -144,16 +144,16 @@ export default {
144144
mergeVNodeHook(oldData, 'afterLeave', () => {
145145
this._leaving = false
146146
this.$forceUpdate()
147-
})
147+
}, key)
148148
return placeholder(h, rawChild)
149149
} else if (mode === 'in-out') {
150150
var delayedLeave
151151
var performLeave = () => { delayedLeave() }
152-
mergeVNodeHook(data, 'afterEnter', performLeave)
153-
mergeVNodeHook(data, 'enterCancelled', performLeave)
152+
mergeVNodeHook(data, 'afterEnter', performLeave, key)
153+
mergeVNodeHook(data, 'enterCancelled', performLeave, key)
154154
mergeVNodeHook(oldData, 'delayLeave', leave => {
155155
delayedLeave = leave
156-
})
156+
}, key)
157157
}
158158
}
159159

src/platforms/web/runtime/modules/transition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function enter (vnode: VNodeWithData) {
100100
pendingNode.elm._leaveCb()
101101
}
102102
enterHook && enterHook(el, cb)
103-
})
103+
}, 'transition-insert')
104104
}
105105

106106
// start enter transition

0 commit comments

Comments
 (0)