Skip to content

Commit

Permalink
make var system expandable (#4175)
Browse files Browse the repository at this point in the history
* make var system expandable

* use old syntax

* remove newer features

* that's a weird error

* remove unnecessary error message

* remove hacky getattr as it's no longer necessary

* improve color handling

* get it right pyright

* dang it darglint

* fix prototype to string

* don't try twice

* adjust test case

* add test for var alpha

* change place of type ignore

* fix json

* add name to custom var operation

* don't delete that you silly

* change logic

* remove extra word
  • Loading branch information
adhami3310 authored Oct 22, 2024
1 parent f39e8c9 commit 54ad9f0
Show file tree
Hide file tree
Showing 8 changed files with 668 additions and 617 deletions.
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.utils.types import ArgsSpec, GenericType
from reflex.vars import VarData
from reflex.vars.base import (
LiteralNoneVar,
LiteralVar,
ToOperation,
Var,
)
from reflex.vars.function import (
Expand Down Expand Up @@ -1254,7 +1251,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 @@ -1315,7 +1312,7 @@ def create(
)


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


Expand Down Expand Up @@ -1384,32 +1381,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[Any]]
Expand Down Expand Up @@ -1537,8 +1508,6 @@ class EventNamespace(types.SimpleNamespace):
LiteralEventVar = LiteralEventVar
EventChainVar = EventChainVar
LiteralEventChainVar = LiteralEventChainVar
ToEventVarOperation = ToEventVarOperation
ToEventChainVarOperation = ToEventChainVarOperation
EventType = EventType

__call__ = staticmethod(event_handler)
Expand Down
Loading

0 comments on commit 54ad9f0

Please sign in to comment.