forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-slots.js
34 lines (30 loc) · 804 Bytes
/
add-slots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// @flow
import { compileToFunctions } from 'vue-template-compiler'
function createVNodesForSlot (
h: Function,
slotValue: SlotValue,
name: string
): Array<VNode> {
const el = typeof slotValue === 'string'
? compileToFunctions(slotValue)
: slotValue
const vnode = h(el)
vnode.data.slot = name
return vnode
}
export function createSlotVNodes (
h: Function,
slots: SlotsObject
): Array<VNode> {
return Object.keys(slots).reduce((acc, key) => {
const content = slots[key]
if (Array.isArray(content)) {
const nodes = content.reduce((accInner, slotDef) => {
return accInner.concat(createVNodesForSlot(h, slotDef, key))
}, [])
return acc.concat(nodes)
} else {
return acc.concat(createVNodesForSlot(h, content, key))
}
}, [])
}