File tree 1 file changed +12
-11
lines changed
1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 1
1
import { h } from '@magic/hyperapp'
2
2
3
3
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 ) ) {
11
13
children = props
12
14
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 = { }
17
18
}
18
19
}
19
20
You can’t perform that action at this time.
0 commit comments