我有两个相关的动作应该一个接一个地触发。

我想用@effectsreducers

在我的slider.component中,我触发了第一个父操作

valueChange(event: MatSliderChange) {
  this.store.dispatch(
    new SetSelectDateTime({ dateSelect: this.date, timeSelect: event.source.displayValue })
  );
}


然后在减速器中

case ESelectDateTimeActionTypes.SetSelectDateTime: {

  return {
    ...state,
    dateTimeSelect: action.payload
  };
}


现在,我应该根据选择的时间触发第二个操作以获取新数据
所以我创建了一个效果updateActualTrips

export class SchedulingsEffects {
  constructor(
    private actions$: Actions,
    private apiCallsService: ApiCallsService
  ) {}
  loadSchedulings$ = createEffect(() =>
    this.actions$.pipe(
      ofType(ESchedulesActions.GetSchedulesByDate),
      mergeMap(() =>
        this.apiCallsService.getSchedulings().pipe(
          map(trips => ({ type: ESchedulesActions.GetSchedulesByDateSuccess, payload: trips })),
          catchError(() => EMPTY)
        )
      )
    )
  );

  $LoadKpiMission = createEffect(() =>
    this.actions$.pipe(
      ofType<any>(EKpiActions.GetMissionsByStation),
      mergeMap(action =>
        this.apiCallsService.getKpiMissionByStation(action.payload, '2016-04-18').pipe(
          map(trips => ({ type: EKpiActions.GetMissionsByStationSuccess, payload: trips })),
          catchError(() => EMPTY)
        )
      )
    )
  );
  $updateActualTrips = createEffect(() =>
    this.actions$.pipe(
      ofType<any>(ESelectDateTimeActionTypes.SetSelectDateTime),
      map(action => ({ type: ESchedulesActions.GetNextSchedulesByTime, payload: action.payload }))
    )
  );
}


问题是效果从未触发,但所选时间已更新

更新资料
我注意到SetSelectDateTime初始化时第一次触发了效果

最佳答案

在您的示例代码中,等待动作ESchedulesActions.GetNextSchedulesByTime没有任何效果,您正在等待的其他动作只有ESchedulesActions.GetSchedulesByDateEKpiActions.GetMissionsByStation

您是否在这里缺少实际效果,还是看不到完整的代码?调度SetSelectDateTime时,您的代码中不会要求API提供新数据。

还是您说的是ESchedulesActions.GetNextSchedulesByTime从来没有首先分发到商店(运行监听SetSelectDateTime的效果时)?

08-06 07:05