Skip to content

Commit

Permalink
Ensure EventCallback exposes EventActionsMixin properties
Browse files Browse the repository at this point in the history
  • Loading branch information
masenf committed Feb 7, 2025
1 parent b3b79a6 commit 0adc4c4
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions reflex/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from typing_extensions import (
Protocol,
Self,
TypeAliasType,
TypedDict,
TypeVar,
Expand Down Expand Up @@ -110,7 +111,7 @@ class EventActionsMixin:
event_actions: Dict[str, Union[bool, int]] = dataclasses.field(default_factory=dict)

@property
def stop_propagation(self):
def stop_propagation(self) -> Self:
"""Stop the event from bubbling up the DOM tree.
Returns:
Expand All @@ -122,7 +123,7 @@ def stop_propagation(self):
)

@property
def prevent_default(self):
def prevent_default(self) -> Self:
"""Prevent the default behavior of the event.
Returns:
Expand All @@ -133,7 +134,7 @@ def prevent_default(self):
event_actions={"preventDefault": True, **self.event_actions},
)

def throttle(self, limit_ms: int):
def throttle(self, limit_ms: int) -> Self:
"""Throttle the event handler.
Args:
Expand All @@ -147,7 +148,7 @@ def throttle(self, limit_ms: int):
event_actions={"throttle": limit_ms, **self.event_actions},
)

def debounce(self, delay_ms: int):
def debounce(self, delay_ms: int) -> Self:
"""Debounce the event handler.
Args:
Expand All @@ -162,7 +163,7 @@ def debounce(self, delay_ms: int):
)

@property
def temporal(self):
def temporal(self) -> Self:
"""Do not queue the event if the backend is down.
Returns:
Expand Down Expand Up @@ -1773,7 +1774,7 @@ def create(
V5 = TypeVar("V5")


class EventCallback(Generic[Unpack[P]]):
class EventCallback(Generic[Unpack[P]], EventActionsMixin):
"""A descriptor that wraps a function to be used as an event."""

def __init__(self, func: Callable[[Any, Unpack[P]], Any]):
Expand All @@ -1784,24 +1785,6 @@ def __init__(self, func: Callable[[Any, Unpack[P]], Any]):
"""
self.func = func

@property
def prevent_default(self):
"""Prevent default behavior.
Returns:
The event callback with prevent default behavior.
"""
return self

@property
def stop_propagation(self):
"""Stop event propagation.
Returns:
The event callback with stop propagation behavior.
"""
return self

@overload
def __call__(
self: EventCallback[Unpack[Q]],
Expand Down

0 comments on commit 0adc4c4

Please sign in to comment.