RxJS:不安全的 catch 用法和 epics 被禁止并请求嵌套
RxJS: Unsafe catch usage in effects and epics is forbidden and request nesting
我有一个效果,主要思想是用API做一些'magic',主要问题:首先我需要做一个请求,成功后我需要做第二个要求。一切都很好,直到我将我的代码更改为这个(看起来更具可读性):
@Effect()
myEffect$ = this.actions$.pipe(
ofType(actionTypes.SomeDataAction),
withLatestFrom(this.store.select(selectTheAwesome)),
concatMap(([action, awesomeData]) =>
forkJoin([
of(awesomeData),
this.myService.makeFirstMagic(
action.payload.someDataId
)
])
),
concatMap(data => {
const [awesomeData, magicFirst] = data;
return this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
mergeMap(response => {
return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
})
);
}),
catchError((error) => of(new SomeDataActionError({ error })))
);
但结果 ts-lint 失败 RxJS: Unsafe catch usage in effects and epics is forbidden
。
我做错了什么?为什么它曾经使用这样的代码工作(通过 linting)?
@Effect()
myEffect$ = this.actions$.pipe(
ofType(actionTypes.SomeDataAction),
withLatestFrom(this.store.select(selectTheAwesome)),
mergeMap(([action, awesomeData]) => {
return this.myService.makeFirstMagic(action.payload.someDataId).pipe(
mergeMap(magicFirst => {
return this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
mergeMap(response => {
return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
})
);
})
);
}),
catchError(error => of(new SomeDataActionError({ error })))
);
您必须对每个服务方法使用 catchError
,例如
this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
mergeMap(response => {
return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
}),
catchError(....)
);
我有一个效果,主要思想是用API做一些'magic',主要问题:首先我需要做一个请求,成功后我需要做第二个要求。一切都很好,直到我将我的代码更改为这个(看起来更具可读性):
@Effect()
myEffect$ = this.actions$.pipe(
ofType(actionTypes.SomeDataAction),
withLatestFrom(this.store.select(selectTheAwesome)),
concatMap(([action, awesomeData]) =>
forkJoin([
of(awesomeData),
this.myService.makeFirstMagic(
action.payload.someDataId
)
])
),
concatMap(data => {
const [awesomeData, magicFirst] = data;
return this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
mergeMap(response => {
return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
})
);
}),
catchError((error) => of(new SomeDataActionError({ error })))
);
但结果 ts-lint 失败 RxJS: Unsafe catch usage in effects and epics is forbidden
。
我做错了什么?为什么它曾经使用这样的代码工作(通过 linting)?
@Effect()
myEffect$ = this.actions$.pipe(
ofType(actionTypes.SomeDataAction),
withLatestFrom(this.store.select(selectTheAwesome)),
mergeMap(([action, awesomeData]) => {
return this.myService.makeFirstMagic(action.payload.someDataId).pipe(
mergeMap(magicFirst => {
return this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
mergeMap(response => {
return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
})
);
})
);
}),
catchError(error => of(new SomeDataActionError({ error })))
);
您必须对每个服务方法使用 catchError
,例如
this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
mergeMap(response => {
return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
}),
catchError(....)
);