使用@ngrx / store访问reducer中的其他状态片

时间:2017-10-13 07:38:48

标签: redux ngrx ngrx-effects ngrx-store-4.0

考虑到以下情况(并假设我们无法改变州的结构):

StoreModule.forRoot({
  a: aReducer,
  b: {
        b1: b1Reducer,
        b2: b2Reducer
     }
}); 

b1Reducer取决于a的值(例如,因为它包含类似用户信息的内容)。 a中最常用的访问方法(只读)b1Reducer是什么?

我提出的解决方案是使用@ngrx/effects,使用a发送可以在reducer中使用的另一个操作:

@Effect()
augmentAction$ = this.action$
    .ofType(Actions.Action1)
    .withLatestFrom(this.store$)
    .switchMap(([action, state]:[Action, AppState]) => {
        const a = state.a;
        return [new Actions.Action2(a)];
    });

这很有效,但如果在许多reducer中使用a,几乎每个动作都需要重新分配,就很难管理。有没有更好的方法来处理这个?

0 个答案:

没有答案
相关问题