angular - 为什么 Async Await 不能与 Angular @Action 一起使用
问题描述
这可行,但如果可能的话,我想在链中添加更多操作。
this.store.dispatch(new UploadPendingFiles(pendingFiles));
this.actions$.pipe(ofActionSuccessful(UploadPendingFiles)).subscribe(() => {
alert('UploadPendingFilesComplete');
this.store.dispatch(new CreateEmailLink(this.getPayload())).subscribe(
() => {
this.sent.emit('true');
},
(error) => {
console.log(error);
this.errors$.next(error.messages);
}
);
});
希望这种风格使用更多的异步等待,但它会在错误的时间触发事情。
this.store.dispatch(new UploadPendingFiles(pendingFiles));
alert('UploadPendingFilesComplete');
// Need alert to proc here
await this.actions$.pipe(ofActionSuccessful(UploadPendingFiles));
// await Another @Action
await this.store.dispatch(new CreateEmailLink(this.getPayload()));
// Alert procs here at the moment
@Action 的片段
@Action(UploadPendingFiles)
uploadPendingFiles(ctx: StateContext<DriveStateModel>, action: UploadFiles) {
return this.uploads.start(action.files, config).pipe(
tap((response) => {
}
}
解决方案
async/await 只是一种可以使用的语法Promise
。您不能将它与其他任何东西一起使用,Observable
例如action$
.
等待一个动作的结果有点奇怪,它应该用 a 来完成correlationId
,这使得代码更加复杂。这就是为什么我不想在这些情况下使用 Redux 的 Effect 的原因。
推荐阅读
- java - 如何在浏览器中打开pdf文件
- python-3.x - Python等待/暂停直到特定时间......并在计划结束时停止
- python - 如何从函数内的循环中获取向量/数组输出?
- jboss - Wildfly 服务器多个域?
- python - 如何在 tkinter 中删除多边形?
- git - git 处理更新以前的版本
- c# - Newtonsoft.Json.ReferenceLoopHandling.Ignore 反序列化格式.NET Core 3.1
- django - 在具有外键关系的模型中创建对象
- sql - GROUP BY with CASE WHEN?
- python - 如何更改矩阵python numpy的偏移量