@@ -109,7 +109,7 @@ def stop_propagation(self) -> Self:
109109 """
110110 return dataclasses .replace (
111111 self ,
112- event_actions = {"stopPropagation" : True , ** self . event_actions },
112+ event_actions = {** self . event_actions , "stopPropagation" : True },
113113 )
114114
115115 @property
@@ -121,7 +121,7 @@ def prevent_default(self) -> Self:
121121 """
122122 return dataclasses .replace (
123123 self ,
124- event_actions = {"preventDefault" : True , ** self . event_actions },
124+ event_actions = {** self . event_actions , "preventDefault" : True },
125125 )
126126
127127 def throttle (self , limit_ms : int ) -> Self :
@@ -135,7 +135,7 @@ def throttle(self, limit_ms: int) -> Self:
135135 """
136136 return dataclasses .replace (
137137 self ,
138- event_actions = {"throttle" : limit_ms , ** self . event_actions },
138+ event_actions = {** self . event_actions , "throttle" : limit_ms },
139139 )
140140
141141 def debounce (self , delay_ms : int ) -> Self :
@@ -149,7 +149,7 @@ def debounce(self, delay_ms: int) -> Self:
149149 """
150150 return dataclasses .replace (
151151 self ,
152- event_actions = {"debounce" : delay_ms , ** self . event_actions },
152+ event_actions = {** self . event_actions , "debounce" : delay_ms },
153153 )
154154
155155 @property
@@ -161,7 +161,7 @@ def temporal(self) -> Self:
161161 """
162162 return dataclasses .replace (
163163 self ,
164- event_actions = {"temporal" : True , ** self . event_actions },
164+ event_actions = {** self . event_actions , "temporal" : True },
165165 )
166166
167167
@@ -2211,7 +2211,15 @@ class EventNamespace:
22112211
22122212 @overload
22132213 def __new__ (
2214- cls , func : None = None , * , background : bool | None = None
2214+ cls ,
2215+ func : None = None ,
2216+ * ,
2217+ background : bool | None = None ,
2218+ stop_propagation : bool | None = None ,
2219+ prevent_default : bool | None = None ,
2220+ throttle : int | None = None ,
2221+ debounce : int | None = None ,
2222+ temporal : bool | None = None ,
22152223 ) -> Callable [
22162224 [Callable [[BASE_STATE , Unpack [P ]], Any ]], EventCallback [Unpack [P ]] # pyright: ignore [reportInvalidTypeVarUse]
22172225 ]: ...
@@ -2222,13 +2230,23 @@ def __new__(
22222230 func : Callable [[BASE_STATE , Unpack [P ]], Any ],
22232231 * ,
22242232 background : bool | None = None ,
2233+ stop_propagation : bool | None = None ,
2234+ prevent_default : bool | None = None ,
2235+ throttle : int | None = None ,
2236+ debounce : int | None = None ,
2237+ temporal : bool | None = None ,
22252238 ) -> EventCallback [Unpack [P ]]: ...
22262239
22272240 def __new__ (
22282241 cls ,
22292242 func : Callable [[BASE_STATE , Unpack [P ]], Any ] | None = None ,
22302243 * ,
22312244 background : bool | None = None ,
2245+ stop_propagation : bool | None = None ,
2246+ prevent_default : bool | None = None ,
2247+ throttle : int | None = None ,
2248+ debounce : int | None = None ,
2249+ temporal : bool | None = None ,
22322250 ) -> (
22332251 EventCallback [Unpack [P ]]
22342252 | Callable [[Callable [[BASE_STATE , Unpack [P ]], Any ]], EventCallback [Unpack [P ]]]
@@ -2238,6 +2256,11 @@ def __new__(
22382256 Args:
22392257 func: The function to wrap.
22402258 background: Whether the event should be run in the background. Defaults to False.
2259+ stop_propagation: Whether to stop the event from bubbling up the DOM tree.
2260+ prevent_default: Whether to prevent the default behavior of the event.
2261+ throttle: Throttle the event handler to limit calls (in milliseconds).
2262+ debounce: Debounce the event handler to delay calls (in milliseconds).
2263+ temporal: Whether the event should be temporal.
22412264
22422265 Raises:
22432266 TypeError: If background is True and the function is not a coroutine or async generator. # noqa: DAR402
@@ -2246,6 +2269,30 @@ def __new__(
22462269 The wrapped function.
22472270 """
22482271
2272+ def _build_event_actions ():
2273+ """Build event_actions dict from decorator parameters.
2274+
2275+ Returns:
2276+ Dict of event actions to apply, or empty dict if none specified.
2277+ """
2278+ if not any (
2279+ [stop_propagation , prevent_default , throttle , debounce , temporal ]
2280+ ):
2281+ return {}
2282+
2283+ event_actions = {}
2284+ if stop_propagation is not None :
2285+ event_actions ["stopPropagation" ] = stop_propagation
2286+ if prevent_default is not None :
2287+ event_actions ["preventDefault" ] = prevent_default
2288+ if throttle is not None :
2289+ event_actions ["throttle" ] = throttle
2290+ if debounce is not None :
2291+ event_actions ["debounce" ] = debounce
2292+ if temporal is not None :
2293+ event_actions ["temporal" ] = temporal
2294+ return event_actions
2295+
22492296 def wrapper (
22502297 func : Callable [[BASE_STATE , Unpack [P ]], T ],
22512298 ) -> EventCallback [Unpack [P ]]:
@@ -2281,8 +2328,22 @@ def wrapper(
22812328 object .__setattr__ (func , "__name__" , name )
22822329 object .__setattr__ (func , "__qualname__" , name )
22832330 state_cls ._add_event_handler (name , func )
2284- return getattr (state_cls , name )
2331+ event_callback = getattr (state_cls , name )
2332+
2333+ # Apply decorator event actions
2334+ event_actions = _build_event_actions ()
2335+ if event_actions :
2336+ # Create new EventCallback with updated event_actions
2337+ event_callback = dataclasses .replace (
2338+ event_callback , event_actions = event_actions
2339+ )
2340+
2341+ return event_callback
22852342
2343+ # Store decorator event actions on the function for later processing
2344+ event_actions = _build_event_actions ()
2345+ if event_actions :
2346+ func ._rx_event_actions = event_actions # pyright: ignore [reportFunctionMemberAccess]
22862347 return func # pyright: ignore [reportReturnType]
22872348
22882349 if func is not None :
0 commit comments