optimus
optimus

Reputation: 856

MergeMap conditionally

Is there any RxJS way to conditionally call mergeMap in Angular:

return apiService.myApi.get().pipe(map(res => res), mergeMap(res => this.getPeople(res)))

to something like this:

return apiService.myApi.get().pipe(map(res => res), 
                        someCond ? mergeMap(res => this.getPeople(res)) : null)

Upvotes: 2

Views: 711

Answers (1)

martin
martin

Reputation: 96891

No, but you can just return the original value with of() or use EMPTY to not emit anything further:

return apiService.myApi.get().pipe(
  map(res => res),
  mergeMap(res => someCond ? this.getPeople(res) : of(res)),
);

Upvotes: 2

Related Questions