Skip to content

Commit 874d7fe

Browse files
committedApr 21, 2021
component: handle prehandled components too
1 parent 7d230b5 commit 874d7fe

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed
 

‎src/modules/component.mjs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { h } from '@magic/hyperapp'
22

33
export const component = name => (props = {}, children) => {
4-
if (typeof children === 'undefined') {
5-
if (
6-
typeof props === 'string' ||
7-
typeof props === 'number' ||
8-
typeof props === 'function' ||
9-
Array.isArray(props)
10-
) {
4+
const is = (ele, ...types) => types.some(type => type === typeof ele)
5+
6+
if (is(children, 'undefined')) {
7+
// are there children that have been processed by h already?
8+
if (props.name && props.props && props.children) {
9+
return h(name, {}, [props])
10+
}
11+
12+
if (is(props, 'string', 'number', 'function') || Array.isArray(props)) {
1113
children = props
1214
props = {}
13-
} else if (typeof props.View === 'function') {
14-
const { View, ...p } = props
15-
children = View
16-
props = p
15+
} else if (is(props.View, 'function')) {
16+
children = props.View
17+
props = {}
1718
}
1819
}
1920

0 commit comments

Comments
 (0)
Please sign in to comment.