vue3-yuanma/packages/runtime-core/src/helpers/createSlots.ts
Evan You e4dc03a8b1 feat(types): adjust type exports for manual render function and tooling usage
- v-model and v-show directives are now exposed as public
- compiler-used runtime helpers are now exposed for TS tooling, but marked as @private

close #1329
2020-06-10 14:57:21 -04:00

34 lines
839 B
TypeScript

import { Slot } from '../componentSlots'
import { isArray } from '@vue/shared'
interface CompiledSlotDescriptor {
name: string
fn: Slot
}
/**
* Compiler runtime helper for creating dynamic slots object
* @private
*/
export function createSlots(
slots: Record<string, Slot>,
dynamicSlots: (
| CompiledSlotDescriptor
| CompiledSlotDescriptor[]
| undefined)[]
): Record<string, Slot> {
for (let i = 0; i < dynamicSlots.length; i++) {
const slot = dynamicSlots[i]
// array of dynamic slot generated by <template v-for="..." #[...]>
if (isArray(slot)) {
for (let j = 0; j < slot.length; j++) {
slots[slot[j].name] = slot[j].fn
}
} else if (slot) {
// conditional single slot generated by <template v-if="..." #foo>
slots[slot.name] = slot.fn
}
}
return slots
}