6

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

sabithpocker
  • 15,274
  • 1
  • 42
  • 75
Abrkad
  • 243
  • 1
  • 3
  • 10
  • 1
    https://github.com/SrgSprinkles/AngularWeatherApp/blob/21c167e6ee0c6a29408c30d8d87def63312efb05/src/app/home/effects/dashboard.effects.ts – Sajeetharan May 29 '18 at 03:09
  • @Sajeetharan Thanks for pointing out to the right direction. But now after using the `exhaustMap` my component `ngOnInit` and `constructore` stop getting called? any thoughts? – Abrkad May 29 '18 at 03:37
  • can you post yout ngOnInit code? – Sajeetharan May 29 '18 at 03:38

2 Answers2

4

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()
           )
       })

      );
    }
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
Ritwick Dey
  • 18,464
  • 3
  • 24
  • 37
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()
        );
      })
    );

}

Abrkad
  • 243
  • 1
  • 3
  • 10