【发布时间】:2019-10-18 04:18:39
【问题描述】:
我有以下
createMission$ = this.actions$.pipe(
ofType<featureActions.CreateMissionRequest>(featureActions.ActionTypes.CreateMissionRequest),
withLatestFrom(this.store$.select(MissionsStoreSelectors.getById(), {id : action.payload.routeId}))
switchMap((action) =>
this.dataService.createMission(action.payload.mission).pipe(
map(response => new featureActions.CreateMissionSuccess({response, mission : action.payload.mission})),
catchError((error: HttpErrorResponse) => {
this.snackBar.open(this.translate.instant('ERROR.HTTP.GENERIC'), this.translate.instant('BUTTON.OK'), {duration: 2500});
return of(new featureActions.CreateMissionFailed({error}));
}),
),
),
);
问题是,在 withLatestFrom 中,我想在选择器中使用来自操作的参数。我如何做到这一点?
withLatestFrom(this.store$.select(MissionsStoreSelectors.getById(), {id : action.payload.routeId}))
switchMap((action, valueFromLatest) =>
编辑:我试过了
@Effect()
createMission$ = this.actions$.pipe(
ofType<featureActions.CreateMissionRequest>(featureActions.ActionTypes.AssignMissionRequest),
withLatestFrom((action) => this.store$.select(MissionsStoreSelectors.getById(), {id : action.payload.routeId})),
switchMap((mission, action) =>
this.dataService.createMission(action.payload.mission).pipe(
map(response => new featureActions.CreateMissionSuccess({response, mission : action.payload.mission})),
catchError((error: HttpErrorResponse) => {
this.snackBar.open(this.translate.instant('ERROR.HTTP.GENERIC'), this.translate.instant('BUTTON.OK'), {duration: 2500});
return of(new featureActions.CreateMissionFailed({error}));
}),
),
),
);
但我在 action.payload 上有类型错误(action 变成了一个数字)似乎不起作用
【问题讨论】:
-
不是你自己定义的选择器jsut方法吗?那么没有什么能阻止你向他们添加过滤器
-
我知道,问题是我不知道如何从 switchmap 外部访问操作以进入 withLatestFrom
-
尝试做这样的事情:
(action)=>withLatestFrom(this.store$.select(MissionsStoreSelectors.getById(), {id : action.payload.routeId}))用调试器看看你得到了什么