
* delete most references to varr * [REF-3562][REF-3563] Replace chakra usage (#3872) * only one mention of var * delete vars.py why not * remove reflex.vars * rename immutable var to var * rename ivars to vars * add vars back smh * ruff * no more create_safe * reorder deprecated * remove raises * remove all Var.create * move to new api * fix unit tests * fix pyi hopefully * sort literals * fix event handler issues * update poetry * fix silly issues i'm very silly * add var_operation_return * rename immutable to not immutable * add str type * it's ruff out there --------- Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com>
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""A bare component."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Iterator
|
|
|
|
from reflex.components.component import Component
|
|
from reflex.components.tags import Tag
|
|
from reflex.components.tags.tagless import Tagless
|
|
from reflex.vars.base import Var
|
|
|
|
|
|
class Bare(Component):
|
|
"""A component with no tag."""
|
|
|
|
contents: Var[Any]
|
|
|
|
@classmethod
|
|
def create(cls, contents: Any) -> Component:
|
|
"""Create a Bare component, with no tag.
|
|
|
|
Args:
|
|
contents: The contents of the component.
|
|
|
|
Returns:
|
|
The component.
|
|
"""
|
|
if isinstance(contents, Var):
|
|
return cls(contents=contents)
|
|
else:
|
|
contents = str(contents) if contents is not None else ""
|
|
return cls(contents=contents) # type: ignore
|
|
|
|
def _render(self) -> Tag:
|
|
if isinstance(self.contents, Var):
|
|
return Tagless(contents=f"{{{str(self.contents)}}}")
|
|
return Tagless(contents=str(self.contents))
|
|
|
|
def _get_vars(self, include_children: bool = False) -> Iterator[Var]:
|
|
"""Walk all Vars used in this component.
|
|
|
|
Args:
|
|
include_children: Whether to include Vars from children.
|
|
|
|
Yields:
|
|
The contents if it is a Var, otherwise nothing.
|
|
"""
|
|
yield self.contents
|