Skip to content

Commit

Permalink
ensure oldVnode always has data during patch
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 28, 2016
1 parent 3c523f2 commit 82f4981
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/core/vdom/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import VNode from './vnode'
import { isPrimitive, _toString, warn } from '../util/index'

const emptyNode = new VNode('', {}, [])
const emptyData = {}
const emptyNode = new VNode('', emptyData, [])
const hooks = ['create', 'update', 'postpatch', 'remove', 'destroy']

function isUndef (s) {
Expand Down Expand Up @@ -267,13 +268,18 @@ export function createPatchFunction (backend) {
function patchVnode (oldVnode, vnode, insertedVnodeQueue) {
if (oldVnode === vnode) return
let i, hook
if (isDef(i = vnode.data) && isDef(hook = i.hook) && isDef(i = hook.prepatch)) {
i(oldVnode, vnode)
const hasData = isDef(i = vnode.data)
if (hasData) {
// ensure the oldVnode also has data during patch
oldVnode.data = oldVnode.data || emptyData
if (isDef(hook = i.hook) && isDef(i = hook.prepatch)) {
i(oldVnode, vnode)
}
}
const elm = vnode.elm = oldVnode.elm
const oldCh = oldVnode.children
const ch = vnode.children
if (isDef(vnode.data)) {
if (hasData) {
for (i = 0; i < cbs.update.length; ++i) cbs.update[i](oldVnode, vnode)
if (isDef(hook) && isDef(i = hook.update)) i(oldVnode, vnode)
}
Expand All @@ -291,7 +297,7 @@ export function createPatchFunction (backend) {
} else if (oldVnode.text !== vnode.text) {
nodeOps.setTextContent(elm, vnode.text)
}
if (isDef(vnode.data)) {
if (hasData) {
for (i = 0; i < cbs.postpatch.length; ++i) cbs.postpatch[i](oldVnode, vnode)
if (isDef(hook) && isDef(i = hook.postpatch)) i(oldVnode, vnode)
}
Expand Down

0 comments on commit 82f4981

Please sign in to comment.