如何用未弃用的方法替换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 }));
        })
      )
    )));
iCMS 回答:如何用未弃用的方法替换rxJs中的方法'combineLatest'?

由于似乎您只需要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(...));
本文链接:https://www.f2er.com/1631057.html

大家都在问