should invoke destroy hook for replaced root nodes too

This commit is contained in:
Evan You 2016-05-28 21:05:53 -04:00
parent 5aeb7f5eef
commit 99a96d3c37
2 changed files with 6 additions and 2 deletions

View File

@ -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)
}
}
}

View File

@ -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', () => {