-1

我使用combinlatestrsjx/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 }));
        })
      )
    )));
4

2 回答 2

4

您需要从rxjsnot导入rxjs/oeprators并像这样使用它:

import { combineLatest } from 'rxjs';

combineLatest([
  this.actions$.pipe(ofType(ActionType.A)),
  this.service.getoc()
]).pipe(mergeMap(...));
于 2020-09-03T11:18:13.560 回答
1

由于您似乎只需要返回的值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
      })
    ))
  )
)
于 2020-09-03T10:32:39.353 回答