How to return a `forkJoin` observable when piping the operators

我们两清 提交于 2019-12-01 06:06:41

问题


Before I had this resolver that just worked fine:

resolve() {
    return forkJoin(
        this.getData1(),
        this.getData2(),
        this.getData3()
    );
}

Now I have to do something like that which is actually does not work:

  resolve() {
    return this.actions$
      .pipe(
        ofActionSuccessful(SomeSctonSuccess),
        forkJoin(
           this.getData1(),
           this.getData2(),
           this.getData3()
        )
      );
    }

as I am hitting this error:

Argument of type 'Observable<[any, any, any, any]>' is not assignable to parameter of type 'OperatorFunction'. Type 'Observable<[any, any, any, any]>' provides no match for the signature '(source: Observable): Observable'.

Any ideas how to fix?

Now I heed to return my forkJoin only after ofActionSuccessful(SomeSctonSuccess) is taking place https://ngxs.gitbook.io/ngxs/advanced/action-handlers


回答1:


Use exhaustMap operator. It maps to inner observable, ignore other values until that observable completes

import { forkJoin } from 'rxjs';
import { exhaustMap } from 'rxjs/operators';

resolve() {
    return this.actions$
      .pipe(
        ofActionSuccessful(SomeSctonSuccess),
        exhaustMap(() => {
         return forkJoin(
             this.getData1(),
             this.getData2(),
             this.getData3()
           )
       })

      );
    }



回答2:


Thanks to @Sajeetharan by looking to this url ended up using exhaustMap

  resolve() {
    return this.actions$.pipe(
      ofActionSuccessful(LoadOnPremHostSuccess),
      exhaustMap(() => {
        return forkJoin(
          this.getData1(),
           this.getData2(),
           this.getData3()
        );
      })
    );

}



来源:https://stackoverflow.com/questions/50575525/how-to-return-a-forkjoin-observable-when-piping-the-operators

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!