|
@@ -94,6 +94,13 @@ class Component(Base, ABC):
|
|
Raises:
|
|
Raises:
|
|
TypeError: If an invalid prop is passed.
|
|
TypeError: If an invalid prop is passed.
|
|
"""
|
|
"""
|
|
|
|
+ # Set the id and children initially.
|
|
|
|
+ initial_kwargs = {
|
|
|
|
+ "id": kwargs.get("id"),
|
|
|
|
+ "children": kwargs.get("children", []),
|
|
|
|
+ }
|
|
|
|
+ super().__init__(**initial_kwargs)
|
|
|
|
+
|
|
# Get the component fields, triggers, and props.
|
|
# Get the component fields, triggers, and props.
|
|
fields = self.get_fields()
|
|
fields = self.get_fields()
|
|
triggers = self.get_triggers()
|
|
triggers = self.get_triggers()
|
|
@@ -264,17 +271,15 @@ class Component(Base, ABC):
|
|
events=events, state_name=state_name, full_control=full_control
|
|
events=events, state_name=state_name, full_control=full_control
|
|
)
|
|
)
|
|
|
|
|
|
- @classmethod
|
|
|
|
- def get_triggers(cls) -> Set[str]:
|
|
|
|
|
|
+ def get_triggers(self) -> Set[str]:
|
|
"""Get the event triggers for the component.
|
|
"""Get the event triggers for the component.
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
The event triggers.
|
|
The event triggers.
|
|
"""
|
|
"""
|
|
- return EVENT_TRIGGERS | set(cls.get_controlled_triggers())
|
|
|
|
|
|
+ return EVENT_TRIGGERS | set(self.get_controlled_triggers())
|
|
|
|
|
|
- @classmethod
|
|
|
|
- def get_controlled_triggers(cls) -> Dict[str, Var]:
|
|
|
|
|
|
+ def get_controlled_triggers(self) -> Dict[str, Var]:
|
|
"""Get the event triggers that pass the component's value to the handler.
|
|
"""Get the event triggers that pass the component's value to the handler.
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
@@ -488,7 +493,7 @@ class Component(Base, ABC):
|
|
|
|
|
|
# Add the hook code for the children.
|
|
# Add the hook code for the children.
|
|
for child in self.children:
|
|
for child in self.children:
|
|
- code.update(child.get_hooks())
|
|
|
|
|
|
+ code |= child.get_hooks()
|
|
|
|
|
|
return code
|
|
return code
|
|
|
|
|
|
@@ -502,6 +507,20 @@ class Component(Base, ABC):
|
|
return None
|
|
return None
|
|
return format.format_ref(self.id)
|
|
return format.format_ref(self.id)
|
|
|
|
|
|
|
|
+ def get_refs(self) -> Set[str]:
|
|
|
|
+ """Get the refs for the children of the component.
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ The refs for the children.
|
|
|
|
+ """
|
|
|
|
+ refs = set()
|
|
|
|
+ ref = self.get_ref()
|
|
|
|
+ if ref is not None:
|
|
|
|
+ refs.add(ref)
|
|
|
|
+ for child in self.children:
|
|
|
|
+ refs |= child.get_refs()
|
|
|
|
+ return refs
|
|
|
|
+
|
|
def get_custom_components(
|
|
def get_custom_components(
|
|
self, seen: Optional[Set[str]] = None
|
|
self, seen: Optional[Set[str]] = None
|
|
) -> Set[CustomComponent]:
|
|
) -> Set[CustomComponent]:
|
|
@@ -565,7 +584,7 @@ class CustomComponent(Component):
|
|
library = f"/{constants.COMPONENTS_PATH}"
|
|
library = f"/{constants.COMPONENTS_PATH}"
|
|
|
|
|
|
# The function that creates the component.
|
|
# The function that creates the component.
|
|
- component_fn: Callable[..., Component]
|
|
|
|
|
|
+ component_fn: Callable[..., Component] = Component.create
|
|
|
|
|
|
# The props of the component.
|
|
# The props of the component.
|
|
props: Dict[str, Any] = {}
|
|
props: Dict[str, Any] = {}
|