feat(compiler): support v-for on named slots

This commit is contained in:
Evan You
2019-10-02 23:10:41 -04:00
parent f401ac6b88
commit fc47029ed3
18 changed files with 645 additions and 277 deletions

View File

@@ -0,0 +1,26 @@
import { Slot } from '../componentSlots'
import { isArray } from '@vue/shared'
interface CompiledSlotDescriptor {
name: string
fn: Slot
}
export function createSlots(
slots: Record<string, Slot>,
dynamicSlots: (CompiledSlotDescriptor | CompiledSlotDescriptor[])[]
): 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[i].name] = slot[i].fn
}
} else {
// conditional single slot generated by <template v-if="..." #foo>
slots[slot.name] = slot.fn
}
}
return slots
}

View File

@@ -43,6 +43,7 @@ export { renderList } from './helpers/renderList'
export { toString } from './helpers/toString'
export { toHandlers } from './helpers/toHandlers'
export { renderSlot } from './helpers/renderSlot'
export { createSlots } from './helpers/createSlots'
export { capitalize, camelize } from '@vue/shared'
// Internal, for integration with runtime compiler