Browse Source

extract getRealChild for abstract components

Evan You 9 years ago
parent
commit
9421bd4806

+ 1 - 4
flow/vnode.js

@@ -44,10 +44,7 @@ declare interface VNodeData {
   staticAttrs?: { [key: string]: string };
   hook?: { [key: string]: Function };
   on?: { [key: string]: Function | Array<Function> };
-  transition?: {
-    definition: String | Object,
-    appear: boolean
-  };
+  transition?: string | Object;
   inlineTemplate?: {
     render: Function,
     staticRenderFns: Array<Function>

+ 1 - 11
src/core/components/keep-alive.js

@@ -1,4 +1,5 @@
 import { callHook } from 'core/instance/lifecycle'
+import { getRealChild } from 'core/vdom/helpers'
 
 export default {
   name: 'keep-alive',
@@ -30,14 +31,3 @@ export default {
     }
   }
 }
-
-// in case the child is also an abstract component, e.g. <transition-control>
-// we want to recrusively retrieve the real component to be rendered
-function getRealChild (vnode) {
-  const compOptions = vnode && vnode.componentOptions
-  if (compOptions && compOptions.Ctor.options._abstract) {
-    return getRealChild(compOptions.propsData.child)
-  } else {
-    return vnode
-  }
-}

+ 1 - 1
src/core/instance/lifecycle.js

@@ -86,7 +86,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
       vm.$el.__vue__ = vm
     }
     // update parent vnode element after patch
-    const parentNode = vm.$options._parentVnode
+    const parentNode = vm.$vnode
     if (parentNode) {
       parentNode.elm = vm.$el
       // update parent $el if the parent is HOC

+ 11 - 0
src/core/vdom/helpers.js

@@ -62,6 +62,17 @@ function applyNS (vnode, ns) {
   }
 }
 
+// in case the child is also an abstract component, e.g. <transition-control>
+// we want to recrusively retrieve the real component to be rendered
+export function getRealChild (vnode) {
+  const compOptions = vnode && vnode.componentOptions
+  if (compOptions && compOptions.Ctor.options._abstract) {
+    return getRealChild(compOptions.propsData.child)
+  } else {
+    return vnode
+  }
+}
+
 export function updateListeners (
   on: Object,
   oldOn: Object,

+ 2 - 1
src/platforms/web/runtime/components/transition-control.js

@@ -1,6 +1,7 @@
 /* flow */
 
 import { warn } from 'core/util/index'
+import { getRealChild } from 'core/vdom/helpers'
 
 export default {
   name: 'transition-control',
@@ -20,7 +21,7 @@ export default {
   },
   render () {
     const oldChild = this._vnode
-    const newChild = this.child
+    const newChild = getRealChild(this.child)
     if (oldChild && oldChild.data && (
       oldChild.tag !== newChild.tag ||
       oldChild.key !== newChild.key