@@ -6,13 +6,24 @@ import {
6
6
ReactHTML ,
7
7
Attributes ,
8
8
} from 'react' ;
9
- import { incorporate } from './incorporate' ;
10
- import { hasModuleProps } from './Modulizer' ;
9
+ import { incorporate , setIncorporator } from './incorporate' ;
10
+ import { setModules , hasModuleProps , Modulizer } from './Modulizer' ;
11
+ import Incorporator from './Incorporator' ;
11
12
12
13
export type PropsExtensions = {
13
14
sel ?: string | symbol ;
14
15
} ;
15
16
17
+ let shouldIncorporate = props => props . sel
18
+
19
+ export function useModules ( modules : any ) {
20
+ if ( ! modules || typeof modules !== 'object' ) return
21
+
22
+ setModules ( modules ) ;
23
+ shouldIncorporate = props => props . sel || hasModuleProps ( props )
24
+ setIncorporator ( Modulizer )
25
+ }
26
+
16
27
type PropsLike < P > = P & PropsExtensions & Attributes ;
17
28
18
29
type Children = string | Array < ReactNode > ;
@@ -33,7 +44,7 @@ function hyperscriptProps<P = any>(
33
44
type : ReactType < P > | keyof ReactHTML ,
34
45
props : PropsLike < P > ,
35
46
) : ReactElement < P > {
36
- if ( ! props . sel && ! hasModuleProps ( props ) ) {
47
+ if ( ! shouldIncorporate ( props ) ) {
37
48
return createElement ( type , props ) ;
38
49
} else {
39
50
return createElement ( incorporate ( type ) , props ) ;
@@ -52,7 +63,7 @@ function hyperscriptPropsChildren<P = any>(
52
63
props : PropsLike < P > ,
53
64
children : Children ,
54
65
) : ReactElement < P > {
55
- if ( ! props . sel && ! hasModuleProps ( props ) ) {
66
+ if ( ! shouldIncorporate ( props ) ) {
56
67
return createElementSpreading ( type , props , children ) ;
57
68
} else {
58
69
return createElementSpreading ( incorporate ( type ) , props , children ) ;
0 commit comments