我有以下效果
@Effect()
createMission$ = this.actions$.pipe(
ofType<featureActions.CreateMissionRequest>(featureActions.ActionTypes.CreateMissionRequest),
withLatestFrom(this.store$),
map(([action, state]) => {
return this.dataService.createMission(state.missions.entities[action.payload.routeId])).pipe(
map(response => new featureActions.CreateMissionSuccess({response, mission: state.missions.entities[action.payload.routeId]})),
catchError((error: HttpErrorResponse) => {
return of(new featureActions.CreateMissionFailed({error}));
}),
);
}),
);
我没有像操纵商店那样,在我的代码中有一个选择器,例如=>
export const featureAdapter: EntityAdapter<IMissionRoute> = createEntityAdapter<IMissionRoute>({
selectId: model => model.routeId,
});
export const selectAllEntities: (state: object) => Dictionary<IMissionRoute> = featureAdapter.getSelectors(selectMissionState).selectEntities;
export const getById = () => createSelector(
selectAllEntities,
(entities, props) => entities[props.id]
);
我想在withLatestFrom
中使用它 withLatestFrom((action) => this.store$.pipe(select(MissionsStoreSelectors.getById(), {id : action.payload.routeId}))),
map(([action, mission]) => {
///
}
我面临的问题是,如果我执行以后的实现,我将不会有2个可观察的对象(一个用于执行任务,一个用于执行任务),而只有一个。
我不知道要进行哪些更改才能使其正常工作
答案 0 :(得分:1)
现在,您已经将任务选择逻辑移到了选择器上,看来您不需要@Effect中的操作。
类似的事情应该/可能起作用(下面的未调试代码)。
例如
@Effect()
createMission$ = this.actions$.pipe(
ofType<featureActions.CreateMissionRequest>(featureActions.ActionTypes.CreateMissionRequest),
withLatestFrom((action) => this.store$.pipe(select(MissionsStoreSelectors.getById(), {id : action.payload.routeId}))),
map(_mission => {
return this.dataService.createMission(_mission).pipe(
map(response => new featureActions.CreateMissionSuccess({response, mission: _mission})),
catchError((error: HttpErrorResponse) => {
return of(new featureActions.CreateMissionFailed({error}));
}),
);
}),
);