forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-functional-component.js
51 lines (44 loc) · 1.3 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
40
41
42
43
44
45
46
47
48
49
50
51
// @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,
_Vue: Component
): Component {
if (mountingOptions.context && typeof mountingOptions.context !== 'object') {
throwError('mount.context must be an object')
}
if (mountingOptions.slots) {
validateSlots(mountingOptions.slots)
}
const context =
mountingOptions.context ||
component.FunctionalRenderContext ||
{}
const listeners = mountingOptions.listeners
if (listeners) {
Object.keys(listeners).forEach(key => {
context.on[key] = listeners[key]
})
}
context.scopedSlots = createScopedSlots(mountingOptions.scopedSlots, _Vue)
return {
render (h: Function) {
return h(
component,
context,
(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
}
}