javascript - NGRX - 在单个效果的多个动作中捕捉动作
问题描述
我有一个效果监听多个动作并执行一些代码,每个动作可能以不同的顺序分派,我需要捕捉第一个和最后一个动作何时被分派并在映射发生之前执行一些逻辑,这是示例代码:
@Effect({dispatch: false})
updated$ = this.actions$.pipe(
ofType(
actionsType.ACTION1,
actionsType.ACTION2,
actionsType.ACTION3,
actionsType.ACTION4,
),
withLatestFrom(this.store$.pipe(
select((state) => state)
)),
map(([action, state]) => {
let objectMapped: {};
objectMapped = buildSomething(state, action.type);
return objectMapped;
}),
tap( (result: any) => {
// I need to know here when the first and the last action happened to do some extra logic.
})
);
解决方案
type
您可以使用 , 的属性检查当前执行的有效操作action
,以执行某些特定代码。
map(action => {
if (action.type === actionsType.ACTION1) {
...
}
})
推荐阅读
- java - 使用 Vert.x 从服务器接收 100-continue 响应时如何检索标头内容?
- flutter - 元素类型 'Set
'不能分配给列表类型'Widget' - cplex - CPLEX 文件夹找不到
- java - 使用 JPA 进行 Spring 缓存
- c# - 从同一模型的父母创建下拉列表
- python-3.x - pandas read_csv 在返回 UnicodeDecodeError: 'utf-8' codec 的特定行上失败
- c++ - 为什么预期
在 LLVM 中为 Expected 实现两个构造函数 &&? - php - 登录到 Osclass oc-admin 面板后出现 Error-500 Error-524
- python - 如果值已经在表中,如何将值插入表中或更新它
- python - 如何以循环方式迭代循环?