【发布时间】:2019-03-27 00:07:35
【问题描述】:
我正在尝试设计一个可以查看对象列表的 ngrx 效果。如果一个 id 在这个列表中,它需要用新的 Id 更新 reducer 并导航到一个新的路由。
如果 id 不在列表中,它只需要导航到新路线。此条件路径有效。 NavigateToNewApp(newPath) 将成功路由到新路径。
(concatMap) 的返回,需要触发两个动作 - SetThingIdSuccess 和 NavigateToNewInternalApp 不起作用。我得到:UserEffects.setAppContext" dispatched an invalid action: {"_isScalar":true}。如果我脱掉 of,那简直是未定义的。
有没有更好的方法来构建这个?从ngrx中的条件语句发送多个效果的最佳方式是什么?
@Effect()
setAppContext = this.actions$.pipe(
ofType(UserActionTypes.DoAPermittedThing),
withLatestFrom(
this.store$.select(getPermittedThingIDs),
this.store$.select(getPermittedThings)
),
map(([thingID, permittedThingIDs, permittedThings]) => {
if (permittedThingIDs.find(id => (thingID as any).payload === id) < 0) {
const newPath = permittedThings[0].Path;
return new NavigateToNewApp(newPath);
}
return of(
concatMap(() => {
const currentId = (thingID as any).payload as number;
return [new SetThingIdSuccess(currentId), new NavigateToNewInternalApp()];
})
})
);
【问题讨论】: