angular - ngrx:存储初始化操作的效果
问题描述
我想在 ngrx 存储初始化(@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
动作过滤器,事件就会被触发。有谁知道初始化操作的过滤器不起作用?
提前致谢。
解决方案
我认为您正在为非根效果寻找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' };
}
}
推荐阅读
- flutter - 在 ListView Flutter 中获取当前可见的小部件
- java - Quartz 重试作业,触发器的延迟时间策略呈指数增加
- firebase - Firestore 中的最大批量删除量
- django - 模板的所见即所得编辑器
- javascript - 使用 javascript 验证多部分表单
- mongodb - Apache NiFi GetMongoProcessor - 不连续生成流文件
- php - 使用 Nginx 服务 PHP 网站不起作用。我的代码或我的设置是否错误?
- java - jOOQ:重用/复制查询
- python - 在本地使用 pyspark 处理大文件
- node.js - 如何在 Windows 上使用 nodejs 递归扫描所有文件夹和文件