]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: use typeFlag in slot normalization
authorEvan You <yyx990803@gmail.com>
Mon, 3 Jun 2019 11:58:12 +0000 (19:58 +0800)
committerEvan You <yyx990803@gmail.com>
Mon, 3 Jun 2019 11:58:12 +0000 (19:58 +0800)
packages/runtime-core/src/componentSlots.ts

index 65ca98426a8ef32af9f93080fba7687cad979716..bdc206d2cdcf5f01b521535384a4d8ee6ad3a1b3 100644 (file)
@@ -1,6 +1,7 @@
 import { ComponentInstance } from './component'
 import { VNode, NormalizedChildren, normalizeVNode, VNodeChild } from './vnode'
-import { isArray, isObject, isFunction } from '@vue/shared'
+import { isArray, isFunction } from '@vue/shared'
+import { SLOTS_CHILDREN } from './typeFlags'
 
 export type Slot = (...args: any[]) => VNode[]
 export type Slots = Readonly<{
@@ -23,14 +24,14 @@ export function resolveSlots(
   children: NormalizedChildren
 ) {
   let slots: Slots | void
-  if (isObject(children) && !isArray(children)) {
+  if (instance.vnode.shapeFlag & SLOTS_CHILDREN) {
     // pre-normalized slots object generated by compiler
     if ((children as any)._normalized) {
       slots = children as Slots
     } else {
       slots = {}
-      for (const key in children) {
-        let value = children[key]
+      for (const key in children as RawSlots) {
+        let value = (children as RawSlots)[key]
         if (isFunction(value)) {
           ;(slots as any)[key] = normalizeSlot(value)
         } else {
@@ -43,9 +44,8 @@ export function resolveSlots(
         }
       }
     }
-  } else if (children != null) {
-    // Array, string or null.
-    // non object children passed to a component
+  } else if (children !== null) {
+    // non slot object children (direct value) passed to a component
     if (__DEV__) {
       // TODO show tip on using functions
       console.log('use function slots!')