fix recursive UI (#4599)
* fix recursive UI * get it right pyright * dang it darglint
This commit is contained in:
parent
880975ae94
commit
0ad0a84ee1
@ -108,11 +108,14 @@ class Bare(Component):
|
|||||||
return Tagless(contents=f"{{{self.contents!s}}}")
|
return Tagless(contents=f"{{{self.contents!s}}}")
|
||||||
return Tagless(contents=str(self.contents))
|
return Tagless(contents=str(self.contents))
|
||||||
|
|
||||||
def _get_vars(self, include_children: bool = False) -> Iterator[Var]:
|
def _get_vars(
|
||||||
|
self, include_children: bool = False, ignore_ids: set[int] | None = None
|
||||||
|
) -> Iterator[Var]:
|
||||||
"""Walk all Vars used in this component.
|
"""Walk all Vars used in this component.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
include_children: Whether to include Vars from children.
|
include_children: Whether to include Vars from children.
|
||||||
|
ignore_ids: The ids to ignore.
|
||||||
|
|
||||||
Yields:
|
Yields:
|
||||||
The contents if it is a Var, otherwise nothing.
|
The contents if it is a Var, otherwise nothing.
|
||||||
|
@ -1020,18 +1020,22 @@ class Component(BaseComponent, ABC):
|
|||||||
event_args.append(spec)
|
event_args.append(spec)
|
||||||
yield event_trigger, event_args
|
yield event_trigger, event_args
|
||||||
|
|
||||||
def _get_vars(self, include_children: bool = False) -> list[Var]:
|
def _get_vars(
|
||||||
|
self, include_children: bool = False, ignore_ids: set[int] | None = None
|
||||||
|
) -> Iterator[Var]:
|
||||||
"""Walk all Vars used in this component.
|
"""Walk all Vars used in this component.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
include_children: Whether to include Vars from children.
|
include_children: Whether to include Vars from children.
|
||||||
|
ignore_ids: The ids to ignore.
|
||||||
|
|
||||||
Returns:
|
Yields:
|
||||||
Each var referenced by the component (props, styles, event handlers).
|
Each var referenced by the component (props, styles, event handlers).
|
||||||
"""
|
"""
|
||||||
vars = getattr(self, "__vars", None)
|
ignore_ids = ignore_ids or set()
|
||||||
|
vars: List[Var] | None = getattr(self, "__vars", None)
|
||||||
if vars is not None:
|
if vars is not None:
|
||||||
return vars
|
yield from vars
|
||||||
vars = self.__vars = []
|
vars = self.__vars = []
|
||||||
# Get Vars associated with event trigger arguments.
|
# Get Vars associated with event trigger arguments.
|
||||||
for _, event_vars in self._get_vars_from_event_triggers(self.event_triggers):
|
for _, event_vars in self._get_vars_from_event_triggers(self.event_triggers):
|
||||||
@ -1075,12 +1079,15 @@ class Component(BaseComponent, ABC):
|
|||||||
# Get Vars associated with children.
|
# Get Vars associated with children.
|
||||||
if include_children:
|
if include_children:
|
||||||
for child in self.children:
|
for child in self.children:
|
||||||
if not isinstance(child, Component):
|
if not isinstance(child, Component) or id(child) in ignore_ids:
|
||||||
continue
|
continue
|
||||||
child_vars = child._get_vars(include_children=include_children)
|
ignore_ids.add(id(child))
|
||||||
|
child_vars = child._get_vars(
|
||||||
|
include_children=include_children, ignore_ids=ignore_ids
|
||||||
|
)
|
||||||
vars.extend(child_vars)
|
vars.extend(child_vars)
|
||||||
|
|
||||||
return vars
|
yield from vars
|
||||||
|
|
||||||
def _event_trigger_values_use_state(self) -> bool:
|
def _event_trigger_values_use_state(self) -> bool:
|
||||||
"""Check if the values of a component's event trigger use state.
|
"""Check if the values of a component's event trigger use state.
|
||||||
@ -1811,19 +1818,25 @@ class CustomComponent(Component):
|
|||||||
for name, prop in self.props.items()
|
for name, prop in self.props.items()
|
||||||
]
|
]
|
||||||
|
|
||||||
def _get_vars(self, include_children: bool = False) -> list[Var]:
|
def _get_vars(
|
||||||
|
self, include_children: bool = False, ignore_ids: set[int] | None = None
|
||||||
|
) -> Iterator[Var]:
|
||||||
"""Walk all Vars used in this component.
|
"""Walk all Vars used in this component.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
include_children: Whether to include Vars from children.
|
include_children: Whether to include Vars from children.
|
||||||
|
ignore_ids: The ids to ignore.
|
||||||
|
|
||||||
Returns:
|
Yields:
|
||||||
Each var referenced by the component (props, styles, event handlers).
|
Each var referenced by the component (props, styles, event handlers).
|
||||||
"""
|
"""
|
||||||
return (
|
ignore_ids = ignore_ids or set()
|
||||||
super()._get_vars(include_children=include_children)
|
yield from super()._get_vars(
|
||||||
+ [prop for prop in self.props.values() if isinstance(prop, Var)]
|
include_children=include_children, ignore_ids=ignore_ids
|
||||||
+ self.get_component(self)._get_vars(include_children=include_children)
|
)
|
||||||
|
yield from filter(lambda prop: isinstance(prop, Var), self.props.values())
|
||||||
|
yield from self.get_component(self)._get_vars(
|
||||||
|
include_children=include_children, ignore_ids=ignore_ids
|
||||||
)
|
)
|
||||||
|
|
||||||
@lru_cache(maxsize=None) # noqa
|
@lru_cache(maxsize=None) # noqa
|
||||||
|
@ -250,8 +250,12 @@ class Form(BaseHTML):
|
|||||||
)
|
)
|
||||||
return form_refs
|
return form_refs
|
||||||
|
|
||||||
def _get_vars(self, include_children: bool = True) -> Iterator[Var]:
|
def _get_vars(
|
||||||
yield from super()._get_vars(include_children=include_children)
|
self, include_children: bool = True, ignore_ids: set[int] | None = None
|
||||||
|
) -> Iterator[Var]:
|
||||||
|
yield from super()._get_vars(
|
||||||
|
include_children=include_children, ignore_ids=ignore_ids
|
||||||
|
)
|
||||||
yield from self._get_form_refs().values()
|
yield from self._get_form_refs().values()
|
||||||
|
|
||||||
def _exclude_props(self) -> list[str]:
|
def _exclude_props(self) -> list[str]:
|
||||||
|
Loading…
Reference in New Issue
Block a user