File tree 3 files changed +37
-31
lines changed
3 files changed +37
-31
lines changed Original file line number Diff line number Diff line change @@ -27,24 +27,26 @@ def has_component(name: str) -> bool:
27
27
logger .debug (f"Skipping { idom_mod_name !r} - does not exist" )
28
28
continue
29
29
30
- if not hasattr (idom_mod , "__all__ " ):
30
+ if not hasattr (idom_mod , "components " ):
31
31
logger .warning (
32
32
f"'django_idom' expected module { idom_mod_name !r} to have an "
33
- "'__all__ ' attribute that lists its publically available components."
33
+ "'components ' attribute that lists its publically available components."
34
34
)
35
35
continue
36
36
37
- for component_name in idom_mod .__all__ :
38
- try :
39
- component_constructor = getattr (idom_mod , component_name )
40
- except AttributeError :
37
+ for component_constructor in idom_mod .components :
38
+ if not callable (component_constructor ):
41
39
logger .warning (
42
- f"Module { idom_mod_name !r } has no attribute { component_name !r } "
40
+ f"{ component_constructor } is not a callable component constructor "
43
41
)
44
42
continue
45
43
46
- if not callable (component_constructor ):
47
- logger .warning (f"'{ idom_mod_name } .{ component_name } ' is not a component" )
44
+ try :
45
+ component_name = getattr (component_constructor , "__name__" )
46
+ except AttributeError :
47
+ logger .warning (
48
+ f"Component constructor { component_constructor } has not attribute '__name__'"
49
+ )
48
50
continue
49
51
50
52
_LOADED_COMPONENTS [f"{ app_mod_name } .{ component_name } " ] = component_constructor
Original file line number Diff line number Diff line change
1
+ import idom
2
+
3
+
4
+ @idom .component
5
+ def HelloWorld ():
6
+ return idom .html .h1 ({"id" : "hello-world" }, "Hello World!" )
7
+
8
+
9
+ @idom .component
10
+ def Button ():
11
+ count , set_count = idom .hooks .use_state (0 )
12
+ return idom .html .div (
13
+ idom .html .button (
14
+ {"id" : "counter-inc" , "onClick" : lambda event : set_count (count + 1 )},
15
+ "Click me!" ,
16
+ ),
17
+ idom .html .p (
18
+ {"id" : "counter-num" , "data-count" : count },
19
+ f"Current count is: { count } " ,
20
+ ),
21
+ )
Original file line number Diff line number Diff line change 1
- import idom
1
+ from . components import Button , HelloWorld
2
2
3
3
4
- __all__ = "HelloWorld" , "Button"
5
-
6
-
7
- @idom .component
8
- def HelloWorld ():
9
- return idom .html .h1 ({"id" : "hello-world" }, "Hello World!" )
10
-
11
-
12
- @idom .component
13
- def Button ():
14
- count , set_count = idom .hooks .use_state (0 )
15
- return idom .html .div (
16
- idom .html .button (
17
- {"id" : "counter-inc" , "onClick" : lambda event : set_count (count + 1 )},
18
- "Click me!" ,
19
- ),
20
- idom .html .p (
21
- {"id" : "counter-num" , "data-count" : count },
22
- f"Current count is: { count } " ,
23
- ),
24
- )
4
+ components = [
5
+ HelloWorld ,
6
+ Button ,
7
+ ]
You can’t perform that action at this time.
0 commit comments