Home
Using Smart NgRX
Demo Walkthrough
API
@smarttools/smart-ngrx / Function

bufferIdsAction

This is an internal function that is used by the Effects to buffer IDs of an action coming into an effect so that we can dispatch them independently but send them to the server in a single request.

NOTE: bufferAction assumes an array of ids is passed to the action it is buffering.

Usage:

load$ = createEffect(
(
actions$ = inject(Actions),
actionService = inject(effectServiceToken),
zone: NgZone = inject(NgZone)
) => {
return actions$.pipe(
ofType(actions.loadByIds),
bufferAction(zone), // <--- buffer the ids
mergeMap((ids) => actionService.loadByIds(ids)),
map((rows) => actions.loadByIdsSuccess({ rows }))
);
},
{ functional: true }
);

Presentation

function bufferIdsAction(
  bufferTime: number = 1,
): (ids: Observable<string[]>) => Observable<string[]>;

Returns

(ids: Observable<string[]>) => Observable<string[]> -

The buffered ids.

Parameters

NameTypeDescription
bufferTime
number

The time to buffer the ids before sending them to the server.