我想在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动作的过滤器不起作用?
提前致谢。
我认为你正在为非根效应寻找ROOT_EFFECTS_INIT或onInitEffects生命周期方法。
来自文档的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' };
}
}