fix: ensure init/prepatch hooks are still repsected

this address a regression introduced in 984927a which
causes vue-router#1338 to resurface.
This commit is contained in:
Evan You 2018-03-23 19:01:24 -04:00
parent a7d190d249
commit de42278d34
2 changed files with 22 additions and 2 deletions

View File

@ -238,10 +238,23 @@ function installComponentHooks (data: VNodeData) {
const hooks = data.hook || (data.hook = {})
for (let i = 0; i < hooksToMerge.length; i++) {
const key = hooksToMerge[i]
hooks[key] = componentVNodeHooks[key]
const existing = hooks[key]
const toMerge = componentVNodeHooks[key]
if (existing !== toMerge && !(existing && existing._merged)) {
hooks[key] = existing ? mergeHook(toMerge, existing) : toMerge
}
}
}
function mergeHook (f1, f2) {
const merged = (a, b, c, d) => {
f1(a, b, c, d)
f2(a, b, c, d)
}
merged._merged = true
return merged
}
// transform component v-model info (value and callback) into
// prop and event handler respectively.
function transformModel (options, data: any) {

View File

@ -393,9 +393,15 @@ describe('vdom patch: edge cases', () => {
extends: Base
}
// sometimes we do need to tap into these internal hooks (e.g. in vue-router)
// so make sure it does work
const inlineHookSpy = jasmine.createSpy('inlineInit')
const vm = new Vue({
render (h) {
const data = { staticClass: 'text-red' }
const data = { staticClass: 'text-red', hook: {
init: inlineHookSpy
}}
return h('div', [
h(Foo, data),
@ -405,5 +411,6 @@ describe('vdom patch: edge cases', () => {
}).$mount()
expect(vm.$el.textContent).toBe('FooBar')
expect(inlineHookSpy.calls.count()).toBe(2)
})
})