Browse Source

should invoke destroy hook for replaced root nodes too

dev
Evan You 9 years ago
parent
commit
99a96d3c37
  1. 2
      src/core/vdom/patch.js
  2. 6
      test/unit/modules/vdom/patch/hooks.spec.js

2
src/core/vdom/patch.js

@ -383,6 +383,8 @@ export function createPatchFunction (backend) {
if (parent !== null) {
nodeOps.insertBefore(parent, vnode.elm, nodeOps.nextSibling(elm))
removeVnodes(parent, [oldVnode], 0, 0)
} else if (isDef(oldVnode.tag)) {
invokeDestroyHook(oldVnode)
}
}
}

6
test/unit/modules/vdom/patch/hooks.spec.js

@ -244,9 +244,10 @@ describe('hooks', () => {
])
const vnode2 = new VNode('div')
patch1(vnode0, vnode1)
expect(destroyed).toBe(1) // should invoke for replaced root nodes too
patch1(vnode1, vnode2)
expect(created).toBe(5)
expect(destroyed).toBe(4)
expect(destroyed).toBe(5)
})
it('should not invoke `create` and `remove` module hook for text nodes', () => {
@ -293,9 +294,10 @@ describe('hooks', () => {
])
const vnode2 = new VNode('div')
patch1(vnode0, vnode1)
expect(destroyed).toBe(1) // should invoke for replaced root nodes too
patch1(vnode1, vnode2)
expect(created).toBe(5)
expect(destroyed).toBe(4)
expect(destroyed).toBe(5)
})
it('should call `create` listener before inserted into parent but after children', () => {

Loading…
Cancel
Save