Просмотр исходного кода

vnode.data.child -> vnode.child

Evan You 10 лет назад
Родитель
Сommit
0a9fa69a01
2 измененных файлов с 15 добавлено и 10 удалено
  1. 5 5
      src/runtime/vdom/component.js
  2. 10 5
      src/runtime/vdom/patch.js

+ 5 - 5
src/runtime/vdom/component.js

@@ -71,11 +71,11 @@ function init (vnode) {
   // the child sets the parent vnode's elm when mounted
   // and when updated.
   child.$mount()
-  data.child = child
+  vnode.child = child
 }
 
 function insert (vnode) {
-  callHook(vnode.data.child, 'ready')
+  callHook(vnode.child, 'ready')
 }
 
 function prepatch (oldVnode, vnode) {
@@ -84,13 +84,13 @@ function prepatch (oldVnode, vnode) {
   if (cur.Ctor !== old.Ctor) {
     // component changed, teardown and create new
     // TODO: keep-alive?
-    old.child.$destroy()
+    oldVnode.child.$destroy()
     init(vnode)
   } else {
-    cur.child = old.child
+    vnode.child = oldVnode.child
     // try re-render child. the child may optimize it
     // and just does nothing.
-    old.child._updateFromParent(cur.data, cur.children, vnode.key)
+    vnode.child._updateFromParent(cur.data, cur.children, vnode.key)
   }
 }
 

+ 10 - 5
src/runtime/vdom/patch.js

@@ -63,9 +63,13 @@ export default function createPatchFunction (backend) {
     const data = vnode.data
     if (isDef(data)) {
       if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode)
-      if (isDef(i = data.child)) {
+      // after calling the init hook, if the vnode is a child component
+      // it should've created a child instance and mounted it. the child
+      // component also has set the placeholder vnode's elm.
+      // in that case we can just return the element and be done.
+      if (isDef(i = vnode.child)) {
         insertedVnodeQueue.push(vnode)
-        return i._vnode.elm
+        return vnode.elm
       }
     }
     const children = vnode.children
@@ -110,7 +114,7 @@ export default function createPatchFunction (backend) {
           invokeDestroyHook(vnode.children[j])
         }
       }
-      if (isDef(i = data.child)) invokeDestroyHook(i._vnode)
+      if (isDef(i = vnode.child)) invokeDestroyHook(i._vnode)
     }
   }
 
@@ -120,7 +124,8 @@ export default function createPatchFunction (backend) {
       let ch = vnodes[startIdx]
       if (isDef(ch)) {
         if (isDef(ch.tag)) {
-          if (isDef(i = ch.data) && isDef(i = i.child)) {
+          // TODO: fix this hack
+          if (isDef(i = ch.child)) {
             i.$destroy()
             ch = i._vnode
           }
@@ -210,7 +215,7 @@ export default function createPatchFunction (backend) {
     }
     // skip child component, which handles its own updates
     // and nodes with v-pre
-    if (isDef(i = vnode.data) && (i.child || i.pre)) {
+    if (vnode.child || (isDef(i = vnode.data) && i.pre)) {
       return
     }
     let elm = vnode.elm = oldVnode.elm