Questions tagged [mergemap]

Questions about mergeMap operator, an RxJS flattening operator to handle observables and emit values.

signature: mergeMap(project: function: Observable, resultSelector: function: any, concurrent: number): Observable

mergeMap offers full control over asynchronicity - both when new elements are created/emitted and how many elements from the source stream should be processed concurrently. For example: assume a source stream emitted 10 elements but maxConcurrency is set to 2 then two first elements will be processed immediately and the rest 8 buffered. Once one of the processed elements is completed, the next element from the source stream will be processed and so on.

54 questions
0
votes
1 answer

RxJS how to call multi API with conditional

My situation: If A is true { Call API 1 If B is true { Call API 2 } else { If B is true { Call API 2 } } My current solution if (A) { this.aservice.getA().subscribe((resA) => { if (B) { this.bservice.getB().subscribe((resB) => { …
David
  • 3
  • 1
0
votes
1 answer

How can I concatenate results of two observables using mergemap

Got stuck on mergemap while learning rxjs. I have 2 observables let list1= of(1,2) let list2= of('A','B') and I want to concatenate the results like this: 1A, 1B, 2A, 2B How to accomplish the concatenation inside mergemap block return list1.pipe( …
0
votes
1 answer

RxJS mergeMap: Inner Observable does not get executed

I want to upload multiple files. Before the upload can happen, I need to POST a request which returns a personId so I can link this personId to my upload files in the backend. The postOnboardingRequestDto$ creates a record but the files are not…
Jonas
  • 23
  • 5
0
votes
1 answer

RXJS: Why is mergemap not providing output from multiple inner observables in example?

I am trying to better understand mergemap by recreating a very simple example and it is not behaving as I expected from my understanding of the official description. In this example each successive document click outputs a single result (i.e. the…
Laurence Fass
  • 1,614
  • 3
  • 21
  • 43
0
votes
1 answer

In RxJS what is the difference between putting a mergeMap in a switchMap vs putting a mergeMap after a switchMap?

I don't understand the difference between these two chunks of code, I would expect identical behavior. The first one has a groupBy and mergeMap after the switchMap. The second one has them inside the switchMap. const arraySubject = new…
0
votes
2 answers

Angular + RxJS: How to make parallel request for each item in an array?

I have an array of IDs. For eg: [1,2,3,4]. I would like to make parallel calls and get the result with forkJoin for each element of the array. But below code is not working for me. forkJoin( Array.from(this.question.attachments).map(attachment =>…
Mukil Deepthi
  • 6,072
  • 13
  • 71
  • 156
0
votes
1 answer

How to continue a mergeMap when one fails in Angular

I can't seem to figure out how to continue with a mergeMap in Angular when one fails. I'm stringing together two mergeMap calls on an observable inside pipe. Both finish all their calls, but one of the second merge map calls return an error, so none…
nick
  • 467
  • 1
  • 5
  • 19
0
votes
2 answers

Array of inner subscriptions with rxjs

I'm trying to improve the flattening and reduce the chaining inside my Rxjs code. A REST call of my service getAllItems() returns the following Items[]: [{ id: 101, name: 'Car', owner: 1 }, { id: 102, name: 'Table', owner: 2 }] I have…
Victor Martinez Calvo
  • 1,717
  • 1
  • 12
  • 11
0
votes
1 answer

Avoiding nesting Observables ( mergeMap on complete )

Got this pseudo code for a scraping service that first explores the pagination urls then the subpage urls on the scraped "parent" website const pagination = [["url-1", "url-2", "url-3", "url-4"], ["url-5"]]; const timeInterval =…
Lajos Bela
  • 49
  • 6
0
votes
1 answer

Mergemap Observable which depends from previous gets ignored,with HTTPClient calls, Angular

I want to execute three functions from a service as Observables to pass data until the last one. A component subscribes to them using a MergeMap method but the last function is not even accessed. The service works like this: public…
Dan
  • 49
  • 6
0
votes
3 answers

Calling multiple apis and subscribing to the data using MergeMap

I need to call an api which will return an array of objects. Then I need to loop through all the objects and using an id from each object i need to call another api. Then I am planning to save the data in an array and subscribe, so that I have…
special3220
  • 93
  • 1
  • 10
0
votes
1 answer

Observable Pagination for infinite scroll to stay up to date

I am trying to get my observable to update automatically during pagination. Only Page Trigger When load() is called, the page observable gets triggered, but the subscription observable does not get triggered when it is updated... pageSub = new…
Jonathan
  • 3,893
  • 5
  • 46
  • 77
0
votes
0 answers

How to cancel mergemap while source is array

Hello i use mergemap from rxjs. I use array of object. const list = [{name:'test',url:'https.....'}.....] const source = from(list) .pipe(mergeMap(getFile, null, 4)) .subscribe(saveDB); In my getFile function I do downlaod file using axios to blob…
user2217288
  • 529
  • 2
  • 14
  • 26
0
votes
1 answer

trouble using rxjs with http observable

I am doing a simple http call and getting an array of objects getFruit():Observable { return this.http.get(URL); } the fruit object is export class Fruit { public name: string; public color: string; } the problem code…
Dan Pettis
  • 113
  • 5
0
votes
1 answer

Need mergeMap data (youtube api playlist) with other data (number video of playlist)

I have successfully displayed my playlist but I would like to add the number of videos to each playlist. For that I have to send another request. I can't merge the number of videos in my playlist result Thank you for your help, 3 days without…
Shmuel
  • 11
  • 1