是否可以等待兩個動作,如Promise.all?例如:如何等待@ ngrx/effects中的2個動作
@Effect()
pulic addUser() {
return this.actions$.ofType(user.ADD)
.switchMap(() => {
return this.userService.add();
})
.map(() => {
return new user.AddSuccessAction();
});
}
@Effect()
pulic addUserOptions() {
return this.actions$.ofType(userOptions.ADD)
.switchMap(() => {
return this.userOptionsService.add();
})
.map(() => {
return new userOptions.AddSuccessAction();
});
}
@Effect()
public complete() {
return this.actions$.ofType(user.ADD_SUCCESS, userOptions.ADD_SUCCESS)
// how to make it works like Promise.all ?
.switchMap(() => {
return this.statisticService.add();
})
.map(() => {
return new account.CompleteAction();
});
}
修訂 我想實現的是呈三角行爲Promise.all。如何並行分配兩個效果,等到所有效果都解決後再發送第三個動作。像https://redux-saga.js.org/docs/advanced/RunningTasksInParallel.html一些與承諾這是相當obviouse:
Promise.all([fetch1, fetch2]).then(fetch3);
是否有可能在NGRX /效果?或者在ngrx/effects中是錯誤的方法?
修訂
把答案如下。
你的問題不明確。你能提供更多細節嗎? –