Skip to content

Commit 4b5c59c

Browse files
committed
Ensure EventCallback exposes EventActionsMixin properties (#4772)
1 parent 0875a3e commit 4b5c59c

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

reflex/event.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from typing_extensions import (
2828
Protocol,
29+
Self,
2930
TypeAliasType,
3031
TypedDict,
3132
TypeVar,
@@ -110,7 +111,7 @@ class EventActionsMixin:
110111
event_actions: Dict[str, Union[bool, int]] = dataclasses.field(default_factory=dict)
111112

112113
@property
113-
def stop_propagation(self):
114+
def stop_propagation(self) -> Self:
114115
"""Stop the event from bubbling up the DOM tree.
115116
116117
Returns:
@@ -122,7 +123,7 @@ def stop_propagation(self):
122123
)
123124

124125
@property
125-
def prevent_default(self):
126+
def prevent_default(self) -> Self:
126127
"""Prevent the default behavior of the event.
127128
128129
Returns:
@@ -133,7 +134,7 @@ def prevent_default(self):
133134
event_actions={"preventDefault": True, **self.event_actions},
134135
)
135136

136-
def throttle(self, limit_ms: int):
137+
def throttle(self, limit_ms: int) -> Self:
137138
"""Throttle the event handler.
138139
139140
Args:
@@ -147,7 +148,7 @@ def throttle(self, limit_ms: int):
147148
event_actions={"throttle": limit_ms, **self.event_actions},
148149
)
149150

150-
def debounce(self, delay_ms: int):
151+
def debounce(self, delay_ms: int) -> Self:
151152
"""Debounce the event handler.
152153
153154
Args:
@@ -162,7 +163,7 @@ def debounce(self, delay_ms: int):
162163
)
163164

164165
@property
165-
def temporal(self):
166+
def temporal(self) -> Self:
166167
"""Do not queue the event if the backend is down.
167168
168169
Returns:
@@ -1773,7 +1774,7 @@ def create(
17731774
V5 = TypeVar("V5")
17741775

17751776

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

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

1787-
@property
1788-
def prevent_default(self):
1789-
"""Prevent default behavior.
1790-
1791-
Returns:
1792-
The event callback with prevent default behavior.
1793-
"""
1794-
return self
1795-
1796-
@property
1797-
def stop_propagation(self):
1798-
"""Stop event propagation.
1799-
1800-
Returns:
1801-
The event callback with stop propagation behavior.
1802-
"""
1803-
return self
1804-
18051788
@overload
18061789
def __call__(
18071790
self: EventCallback[Unpack[Q]],

0 commit comments

Comments
 (0)