Skip to content

Commit

Permalink
fix: ensure init/prepatch hooks are still repsected
Browse files Browse the repository at this point in the history
this address a regression introduced in 984927a which
causes vue-router#1338 to resurface.
  • Loading branch information
yyx990803 committed Mar 23, 2018
1 parent a7d190d commit de42278
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/core/vdom/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,21 @@ 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
Expand Down
9 changes: 8 additions & 1 deletion test/unit/modules/vdom/patch/edge-cases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -405,5 +411,6 @@ describe('vdom patch: edge cases', () => {
}).$mount()

expect(vm.$el.textContent).toBe('FooBar')
expect(inlineHookSpy.calls.count()).toBe(2)
})
})

0 comments on commit de42278

Please sign in to comment.