Ensure EventCallback exposes EventActionsMixin properties (#4772)

This commit is contained in:
Masen Furer 2025-02-07 14:57:12 -08:00 committed by GitHub
parent f3220470e8
commit c17cda3e95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,6 +26,7 @@ from typing import (
from typing_extensions import ( from typing_extensions import (
Protocol, Protocol,
Self,
TypeAliasType, TypeAliasType,
TypedDict, TypedDict,
TypeVar, TypeVar,
@ -110,7 +111,7 @@ class EventActionsMixin:
event_actions: Dict[str, Union[bool, int]] = dataclasses.field(default_factory=dict) event_actions: Dict[str, Union[bool, int]] = dataclasses.field(default_factory=dict)
@property @property
def stop_propagation(self): def stop_propagation(self) -> Self:
"""Stop the event from bubbling up the DOM tree. """Stop the event from bubbling up the DOM tree.
Returns: Returns:
@ -122,7 +123,7 @@ class EventActionsMixin:
) )
@property @property
def prevent_default(self): def prevent_default(self) -> Self:
"""Prevent the default behavior of the event. """Prevent the default behavior of the event.
Returns: Returns:
@ -133,7 +134,7 @@ class EventActionsMixin:
event_actions={"preventDefault": True, **self.event_actions}, event_actions={"preventDefault": True, **self.event_actions},
) )
def throttle(self, limit_ms: int): def throttle(self, limit_ms: int) -> Self:
"""Throttle the event handler. """Throttle the event handler.
Args: Args:
@ -147,7 +148,7 @@ class EventActionsMixin:
event_actions={"throttle": limit_ms, **self.event_actions}, 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. """Debounce the event handler.
Args: Args:
@ -162,7 +163,7 @@ class EventActionsMixin:
) )
@property @property
def temporal(self): def temporal(self) -> Self:
"""Do not queue the event if the backend is down. """Do not queue the event if the backend is down.
Returns: Returns:
@ -1773,7 +1774,7 @@ V4 = TypeVar("V4")
V5 = TypeVar("V5") 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.""" """A descriptor that wraps a function to be used as an event."""
def __init__(self, func: Callable[[Any, Unpack[P]], Any]): def __init__(self, func: Callable[[Any, Unpack[P]], Any]):
@ -1784,24 +1785,6 @@ class EventCallback(Generic[Unpack[P]]):
""" """
self.func = func 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 @overload
def __call__( def __call__(
self: EventCallback[Unpack[Q]], self: EventCallback[Unpack[Q]],