Sergiu Molnar
Sergiu Molnar

Reputation: 1020

How to use ofType with more than 5 actions?

I have to use ofType with more than 5 actions in my effect.

@Effect()
  applyInspectionsFilters$: Observable<Action> = this.actions$.pipe(
    ofType(
      InspectionsPageActions.applyInspectionsFilters.type,
      InspectionsPageActions.clearSelectedInspectionsFilters.type,
      InspectionsPageActions.removeSelectedStatusFilter.type,
      InspectionsPageActions.removeSelectedAttributeFilter.type,
      InspectionsPageActions.removeSelectedUserFilter.type,
      InspectionsPageActions.removeNotAssignedUsersFilter.type
    ),
    withLatestFrom(
      this.store$.pipe(select(fromInspections.getSelectedInspectionsFilters))
    ),
    switchMap(([action, filters]) =>
      ...
    )
  );

How should I do this when the maximum number of parameters is 5 in their library?

Upvotes: 16

Views: 12305

Answers (1)

bryan60
bryan60

Reputation: 29335

docs here: https://ngrx.io/api/effects/ofType

show the way to do it is something like this:

ofType(
  ...[InspectionsPageActions.applyInspectionsFilters.type,
  InspectionsPageActions.clearSelectedInspectionsFilters.type,
  InspectionsPageActions.removeSelectedStatusFilter.type,
  InspectionsPageActions.removeSelectedAttributeFilter.type,
  InspectionsPageActions.removeSelectedUserFilter.type,
  InspectionsPageActions.removeNotAssignedUsersFilter.type]
),

Upvotes: 29

Related Questions