|
@@ -24,9 +24,6 @@ from pynecone.style import Style
|
|
|
from pynecone.utils import format, imports, path_ops, types
|
|
|
from pynecone.var import BaseVar, Var
|
|
|
|
|
|
-if typing.TYPE_CHECKING:
|
|
|
- from pynecone.state import State
|
|
|
-
|
|
|
|
|
|
class Component(Base, ABC):
|
|
|
"""The base class for all Pynecone components."""
|
|
@@ -37,9 +34,6 @@ class Component(Base, ABC):
|
|
|
# The style of the component.
|
|
|
style: Style = Style()
|
|
|
|
|
|
- # The app state the component is connected to.
|
|
|
- state: Optional[Type[State]] = None
|
|
|
-
|
|
|
# A mapping from event triggers to event chains.
|
|
|
event_triggers: Dict[str, Union[EventChain, Var]] = {}
|
|
|
|
|
@@ -120,7 +114,7 @@ class Component(Base, ABC):
|
|
|
if types._issubclass(field_type, Var):
|
|
|
try:
|
|
|
# Try to create a var from the value.
|
|
|
- kwargs[key] = Var.create(value, is_string=type(value) == str)
|
|
|
+ kwargs[key] = Var.create(value)
|
|
|
|
|
|
# Check that the var type is not None.
|
|
|
if kwargs[key] is None:
|
|
@@ -365,7 +359,7 @@ class Component(Base, ABC):
|
|
|
children = [
|
|
|
child
|
|
|
if isinstance(child, Component)
|
|
|
- else Bare.create(contents=Var.create(child))
|
|
|
+ else Bare.create(contents=Var.create(child, is_string=True))
|
|
|
for child in children
|
|
|
]
|
|
|
return cls(children=children, **props)
|
|
@@ -399,19 +393,6 @@ class Component(Base, ABC):
|
|
|
child.add_style(style)
|
|
|
return self
|
|
|
|
|
|
- def set_state(self, state: Type[State]):
|
|
|
- """Set the state of the component and its children.
|
|
|
-
|
|
|
- Args:
|
|
|
- state: The state to set.
|
|
|
- """
|
|
|
- # Set the state of the component.
|
|
|
- self.state = state
|
|
|
-
|
|
|
- # Set the state of the children.
|
|
|
- for child in self.children:
|
|
|
- child.set_state(state)
|
|
|
-
|
|
|
def render(self) -> str:
|
|
|
"""Render the component.
|
|
|
|