【发布时间】:2020-10-15 00:59:40
【问题描述】:
我正在调度两个动作,不需要顺序执行。我试过下面的代码:
@Effect()
loadIntResponse$ =
this.actions.ofType(fromActions.LOAD_INT_RESPONSE).pipe(
switchMap(() => {
return this.Service.int().pipe(
tap(x => this.store.dispatch(new fromActions.LoadService(x))),
map(responseResult => {
return new fromActions.LoadIntResponseSuccess(responseResult)
}),
catchError(error => {
let err: responseResult = {
status: "FALSE",
message: error
}
return of(new fromActions.LoadIntResponseFail(err))
})
)
})
)
loadService$ = this.actions.ofType(fromActions.Load_Service).pipe(
switchMap((action: fromActions.LoadService) => {
if (action.payload.status == 'TRUE' {
return this.reuseService.reuseServiceCall().pipe(
map( result ==> {
return of({type: fromActions.LOAD_SERVICE_SUCCESS, payload:
result})
}),
catchError(error => {
let err: responseResult = {
status: "FALSE",
message: error
}
return of(new fromActions.LoadServiceFail(err))
})
)
})
)
但它并没有触发另一个效果LoadService()
预期结果:触发另一个效果LoadService()
LoadService 接受任何类型的参数。
非常感谢您的帮助。谢谢!
【问题讨论】:
-
这个效果应该做什么?你的 catchError 中的返回很可能不起作用。
-
哪个影响LoadService()?
-
不,只是我正在查看的代码
-
这个效果假设调用 service.int() 将返回状态和消息。如果成功,则 LoadIntResponseSuccess 带有来自 service.int() 的响应结果并触发另一个效果 LoadService(x)。 x 也是来自服务调用 this.Service.int() 的响应结果。否则,在 catch 调用失败操作中传递响应结果,状态为 FALSE 并在消息中显示错误消息。
-
好吧,这不是它的工作原理!基本上你想在 fromActions.LoadIntResponseSuccess 发生时调度新的 fromActions.LoadService(x)?