ngrx:对商店INIT操作的影响

问题描述 投票:0回答:1

我想在ngrx store inits(@ngrx/store/init)发送动作。我为此创建了一个效果:

    @Effect()
  reloadConext$ = this.actions$.pipe(
    ofType(INIT),
    switchMap(() => {
      console.log('INIT ACTION');
        //dispatch my action here
        return of([]);
    }

调度store init操作时不会触发该效果。我在app.module中注册了root的效果模块:

EffectsModule.forRoot([AppEffects]),

如果我删除了ofType动作过滤器,则会触发该事件。有谁知道init动作的过滤器不起作用?

提前致谢。

angular ngrx ngrx-store ngrx-effects
1个回答
2
投票

我认为你正在为非根效应寻找ROOT_EFFECTS_INITonInitEffects生命周期方法。

来自文档的ROOT_EFFECTS_INIT:

@Effect()
init$ = this.actions$.pipe(
  ofType(ROOT_EFFECTS_INIT),
  map(action => ...)
);

来自文档的onInitEffects:

class UserEffects implements OnInitEffects {
  ngrxOnInitEffects(): Action {
    return { type: '[UserEffects]: Init' };
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.