vue3-yuanma/packages/runtime-core/src/helpers/renderSlot.ts

31 lines
685 B
TypeScript
Raw Normal View History

2019-10-22 15:26:48 +00:00
import { Data } from '../component'
2019-09-28 00:29:20 +00:00
import { Slot } from '../componentSlots'
import {
VNodeChildren,
openBlock,
createBlock,
Fragment,
VNode
} from '../vnode'
import { PatchFlags } from '@vue/shared'
2019-09-28 00:29:20 +00:00
export function renderSlot(
slots: Record<string, Slot>,
name: string,
2019-10-22 15:26:48 +00:00
props: Data = {},
2019-09-28 00:29:20 +00:00
// this is not a user-facing function, so the fallback is always generated by
2019-10-05 14:48:54 +00:00
// the compiler and guaranteed to be an array
fallback?: VNodeChildren
): VNode {
const slot = slots[name]
return (
openBlock(),
createBlock(
Fragment,
{ key: props.key },
slot ? slot(props) : fallback || [],
slots._compiled ? 0 : PatchFlags.BAIL
)
)
2019-09-28 00:29:20 +00:00
}