Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make var system expandable #4175

Merged
merged 20 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions reflex/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import (
Any,
Callable,
ClassVar,
Dict,
Generic,
List,
Expand All @@ -33,9 +32,7 @@
from reflex.vars import VarData
from reflex.vars.base import (
CachedVarOperation,
LiteralNoneVar,
LiteralVar,
ToOperation,
Var,
cached_property_no_lock,
)
Expand Down Expand Up @@ -1249,7 +1246,7 @@ def get_fn_signature(fn: Callable) -> inspect.Signature:
return signature.replace(parameters=(new_param, *signature.parameters.values()))


class EventVar(ObjectVar):
class EventVar(ObjectVar, python_types=EventSpec):
"""Base class for event vars."""


Expand Down Expand Up @@ -1323,7 +1320,7 @@ def create(
)


class EventChainVar(FunctionVar):
class EventChainVar(FunctionVar, python_types=EventChain):
"""Base class for event chain vars."""


Expand Down Expand Up @@ -1403,32 +1400,6 @@ def create(
)


@dataclasses.dataclass(
eq=False,
frozen=True,
**{"slots": True} if sys.version_info >= (3, 10) else {},
)
class ToEventVarOperation(ToOperation, EventVar):
"""Result of a cast to an event var."""

_original: Var = dataclasses.field(default_factory=lambda: LiteralNoneVar.create())

_default_var_type: ClassVar[Type] = EventSpec


@dataclasses.dataclass(
eq=False,
frozen=True,
**{"slots": True} if sys.version_info >= (3, 10) else {},
)
class ToEventChainVarOperation(ToOperation, EventChainVar):
"""Result of a cast to an event chain var."""

_original: Var = dataclasses.field(default_factory=lambda: LiteralNoneVar.create())

_default_var_type: ClassVar[Type] = EventChain


G = ParamSpec("G")

IndividualEventType = Union[EventSpec, EventHandler, Callable[G, Any], Var]
Expand Down Expand Up @@ -1503,8 +1474,6 @@ class EventNamespace(types.SimpleNamespace):
LiteralEventVar = LiteralEventVar
EventChainVar = EventChainVar
LiteralEventChainVar = LiteralEventChainVar
ToEventVarOperation = ToEventVarOperation
ToEventChainVarOperation = ToEventChainVarOperation
EventType = EventType

__call__ = staticmethod(event_handler)
Expand Down
Loading
Loading