@@ -136,13 +136,13 @@ def _run_actions(self: Store[State, Action, Event]) -> None:
136136 if is_complete_reducer_result (result ):
137137 self ._state = result .state
138138 self ._call_listeners (self ._state )
139- self .dispatch ([* (result .actions or []), * (result .events or [])])
139+ self ._dispatch ([* (result .actions or []), * (result .events or [])])
140140 elif is_state_reducer_result (result ):
141141 self ._state = result
142142 self ._call_listeners (self ._state )
143143
144144 if isinstance (action , FinishAction ):
145- self .dispatch ( cast (Event , FinishEvent ()))
145+ self ._dispatch ([ cast (Event , FinishEvent ())] )
146146
147147 def _run_event_handlers (self : Store [State , Action , Event ]) -> None :
148148 while len (self ._events ) > 0 :
@@ -177,22 +177,37 @@ def wait_for_event_handlers(self: Store[State, Action, Event]) -> None:
177177 """Wait for the event handlers to finish."""
178178 self ._event_handlers_queue .join ()
179179
180+ @overload
180181 def dispatch (
181182 self : Store [State , Action , Event ],
182- * parameters : DispatchParameters [Action , Event ],
183- with_state : Callable [[State | None ], DispatchParameters [Action , Event ]]
184- | None = None ,
183+ * parameters : DispatchParameters [Action ],
184+ ) -> None : ...
185+ @overload
186+ def dispatch (
187+ self : Store [State , Action , Event ],
188+ * ,
189+ with_state : Callable [[State | None ], DispatchParameters [Action ]] | None = None ,
190+ ) -> None : ...
191+ def dispatch (
192+ self : Store [State , Action , Event ],
193+ * parameters : DispatchParameters [Action ],
194+ with_state : Callable [[State | None ], DispatchParameters [Action ]] | None = None ,
185195 ) -> None :
186- """Dispatch actions and/or events ."""
196+ """Dispatch actions."""
187197 if with_state is not None :
188198 self .dispatch (with_state (self ._state ))
189199
190- items = [
191- item
192- for items in parameters
193- for item in (items if isinstance (items , list ) else [items ])
200+ actions = [
201+ action
202+ for actions in parameters
203+ for action in (actions if isinstance (actions , list ) else [actions ])
194204 ]
205+ self ._dispatch (actions )
195206
207+ def _dispatch (
208+ self : Store [State , Action , Event ],
209+ items : list [Action | Event ],
210+ ) -> None :
196211 for item in items :
197212 if isinstance (item , BaseAction ):
198213 action = cast (Action , item )
0 commit comments