如何解决如何用未弃用的方法替换rxJs中的方法'combineLatest'?
我使用combinlatest
rsjx / operator one实现了一种方法,它可以正常工作,但鉴于声纳问题,它已弃用。因此,我需要将其转换为最新的。但我尝试,只是替换导入它给了错误。我需要一些专家帮助才能做到这一点。
gX$ = createEffect(() => this.actions$.pipe(
ofType(ActionType.A),combineLatest(this.service.getoc()),mergeMap(([,oc]) => this.reviewService.findBy(oc.id,new Date(),new Date(new Date().setDate(new Date().getDate() + 1)))
.pipe(
mergeMap(d => {
return of(reviewLoadSuccess({ reviews: getReviews(d) }));
}
),catchError(error => {
return of(reviewLoadFailure({ error: error }));
})
)
)));
解决方法
由于似乎您只需要this.service.getoc()
返回的值,所以我建议使用switchMapTo
运算符,如下所示
gX$ = createEffect(() => this.actions$.pipe(
ofType(ActionType.A),switchMapTo(this.service.getoc()),mergeMap(oc => this.reviewService.findBy(oc.id,new Date(),new Date(new Date().setDate(new Date().getDate() + 1)))
.pipe(
mergeMap(d => {
return of(reviewLoadSuccess({ reviews: getReviews(d) }));
}
),catchError(error => {
return of(reviewLoadFailure({ error: error }));
})
)
)));
如果您还想使用该操作,请考虑应用以下更改:
gX$ = createEffect(() => this.actions$
.pipe(
ofType(ActionType.A),switchMap(action => this.service.getoc().pipe(
switchMap(oc => {
// you have access to both action,and oc
// ... continue running your code
})
))
)
)
,
您需要从rxjs
而不是rxjs/oeprators
导入并像这样使用它:
import { combineLatest } from 'rxjs';
combineLatest([
this.actions$.pipe(ofType(ActionType.A)),this.service.getoc()
]).pipe(mergeMap(...));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。