如何在5个以上的动作中使用ofType?

Ser*_*nar 2 typescript ngrx ngrx-effects angular

我必须在超过5个动作中使用ofType。

@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]) =>
      ...
    )
  );
Run Code Online (Sandbox Code Playgroud)

当其库中参数的最大数量为5时,该怎么办?

bry*_*n60 5

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]
),
Run Code Online (Sandbox Code Playgroud)

  • 与传递以逗号分隔的操作相同 (2认同)