@@ -215,7 +215,7 @@ function incrementSecond(): PartialStateUpdater<{ count2: number }> {
215215## Performing Side Effects
216216
217217Side effects are handled using the ` withEffects ` feature.
218- This feature accepts a function that receives the store instance as an argument and returns a dictionary of effects.
218+ This feature accepts a function that receives the store instance as an argument and returns either a dictionary of effects or an array of effects.
219219Each effect is defined as an observable that reacts to specific events using the ` Events ` service.
220220This service provides the ` on ` method that returns an observable of dispatched events filtered by the specified event types.
221221If an effect returns a new event, that event is automatically dispatched.
@@ -260,6 +260,41 @@ export const BookSearchStore = signalStore(
260260
261261</ngrx-code-example >
262262
263+ <ngrx-docs-alert type =" help " >
264+
265+ In addition to the ` Events ` service, effects can be defined by listening to any other observable source.
266+ It's also possible to return an array of effects from the ` withEffects ` feature.
267+
268+ ``` ts
269+ // ... other imports
270+ import { exhaustMap , tap , timer } from ' rxjs' ;
271+ import { withEffects } from ' @ngrx/signals/events' ;
272+ import { mapResponse } from ' @ngrx/operators' ;
273+ import { BooksService } from ' ./books-service' ;
274+
275+ export const BookSearchStore = signalStore (
276+ // ... other features
277+ withEffects ((store , booksService = inject (BooksService )) => [
278+ timer (0 , 30_000 ).pipe (
279+ exhaustMap (() =>
280+ booksService .getAll ().pipe (
281+ mapResponse ({
282+ next : (books ) => booksApiEvents .loadedSuccess (books ),
283+ error : (error : { message: string }) =>
284+ booksApiEvents .loadedFailure (error .message ),
285+ })
286+ )
287+ )
288+ ),
289+ events
290+ .on (booksApiEvents .loadedFailure )
291+ .pipe (tap (({ payload }) => console .error (payload ))),
292+ ])
293+ );
294+ ```
295+
296+ </ngrx-docs-alert >
297+
263298## Reading State
264299
265300The Events plugin doesn’t change how the state is exposed or consumed.
0 commit comments