Redux 使用@ngrx/store访问reducer中的其他状态片
鉴于以下情况(假设我们无法改变州的结构): 而Redux 使用@ngrx/store访问reducer中的其他状态片,redux,ngrx,ngrx-effects,ngrx-store-4.0,Redux,Ngrx,Ngrx Effects,Ngrx Store 4.0,鉴于以下情况(假设我们无法改变州的结构): 而b1Reducer取决于a的值(例如,因为它包含类似用户信息的内容)。 在b1Reducer中访问(只读)a最惯用的方式是什么 我提出的解决方案是使用@ngrx/effects,使用a调度另一个可以在减速器中使用的操作: @Effect() augmentAction$ = this.action$ .ofType(Actions.Action1) .withLatestFrom(this.store$) .switchMap
b1Reducer
取决于a
的值(例如,因为它包含类似用户信息的内容)。
在b1Reducer
中访问(只读)a
最惯用的方式是什么
我提出的解决方案是使用@ngrx/effects
,使用a
调度另一个可以在减速器中使用的操作:
@Effect()
augmentAction$ = this.action$
.ofType(Actions.Action1)
.withLatestFrom(this.store$)
.switchMap(([action, state]:[Action, AppState]) => {
const a = state.a;
return [new Actions.Action2(a)];
});
这是可行的,但是如果a
在许多减速机中使用,那么几乎每一个操作都需要重新修补,那么就很难管理了。有没有更好的方法来处理这个问题
@Effect()
augmentAction$ = this.action$
.ofType(Actions.Action1)
.withLatestFrom(this.store$)
.switchMap(([action, state]:[Action, AppState]) => {
const a = state.a;
return [new Actions.Action2(a)];
});