我正在尝试制作一个可以做很多事情的效果,并返回一个成功/失败的动作。
这是我正在做的事情的简化版本:
UploadSolidModel$ = this.actions$.pipe(
ofType<featureActions.UploadSolidRequest>(featureActions.ActionTypes.UploadSolidRequest),
switchMap((action) =>
// 1) return an observable with elevation
this.altimeterService.getElevation()
// 2) use the above result to make some change and dispatch an API call that return an observable
.pipe(
switchMap((elevation) =>
this.dataService.uploadSolid()
)
)
// 3.a) use the response from the previous api call to dispatch a success/fail effect
.pipe(
map((response) => {
return new ActionSuccess;
}),
// 3) 3.b) use the failure of the api call to dispatch failure effect
catchError((error: HttpErrorResponse) => {
return of(new featureActions.UploadSolidFailed({ error: error.message }));
})
)
)
我遇到的问题是 NgRx 告诉我我的 effect 正在调度一个无效的动作。 我的链条一定是错的,但我试图修复它,但找不到使这项工作起作用的方法。
答案 0 :(得分:0)
您将在 3a 处返回操作的构造函数。它应该返回一个动作实例。
// notice the `()`
return new ActionSuccess()