wip: use typeFlag in slot normalization

This commit is contained in:
Evan You 2019-06-03 19:58:12 +08:00
parent c442785465
commit ca82c329f0

View File

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