forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-functional-component.js
39 lines (35 loc) · 1.1 KB
/
create-functional-component.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
35
36
37
38
39
// @flow
import { throwError } from 'shared/util'
import { validateSlots } from './validate-slots'
import { createSlotVNodes } from './create-slot-vnodes'
import createScopedSlots from './create-scoped-slots'
export default function createFunctionalComponent (
component: Component,
mountingOptions: Options
): Component {
if (mountingOptions.context && typeof mountingOptions.context !== 'object') {
throwError('mount.context must be an object')
}
if (mountingOptions.slots) {
validateSlots(mountingOptions.slots)
}
const data = mountingOptions.context ||
component.FunctionalRenderContext || {}
data.scopedSlots = createScopedSlots(mountingOptions.scopedSlots)
return {
render (h: Function) {
return h(
component,
data,
(mountingOptions.context &&
mountingOptions.context.children &&
mountingOptions.context.children.map(
x => (typeof x === 'function' ? x(h) : x)
)) ||
createSlotVNodes(this, mountingOptions.slots || {})
)
},
name: component.name,
_isFunctionalContainer: true
}
}