我有一个效果,监听多个动作并做一些代码,每个动作可能以不同的顺序调度,我需要捕捉第一个和最后一个动作被调度的时间,并在映射发生之前执行一些逻辑,以下是示例代码:
@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.
})
);发布于 2019-09-16 23:30:30
您可以使用action的type属性检查当前正在执行的操作,以执行一些特定的代码。
map(action => {
if (action.type === actionsType.ACTION1) {
...
}
})https://stackoverflow.com/questions/57959884
复制相似问题