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
4
votes
2 answers

Using RxJS to build data from multiple API calls

I'm trying to get a better understanding of how to use RxJS Operators to solve a specific problem I'm having. I actually have two problems but they're similar enough. I'm grabbing a bunch of documents from an API endpoint…
qbert
  • 119
  • 2
  • 9
4
votes
2 answers

NgRx effect mergeMap approach

I have two implementations of the same effect, and both work. I'm having a hard time understanding the differences between the two and which is more "correct". Please find them below: Option 1. IDE cannot figure out the type for instance in the last…
xandermonkey
  • 4,054
  • 2
  • 31
  • 53
3
votes
3 answers

RxJS: execute concatMap i parallel

Is it possible to execute a high-order observable in parallel, but still preserve the order when merging the results? I have something looking like this: invoker$: Observable; fetch: (index: number) => Observable; invoker$ .pipe( …
Mikkel R. Lund
  • 2,336
  • 1
  • 31
  • 44
3
votes
2 answers

switchMap combined with mergeMap

I have an Observable where each new value should cause an HTTP request. On the client-side I only care about the latest response value; however, I want every request to complete for monitoring/etc. purposes. What I currently have is something…
Steve D
  • 373
  • 2
  • 17
3
votes
2 answers

using mergeMap in forkJoin to get observables depending one on the other

I have a combination of several async request I need to complete together (doing it with forkJoin) - when doing so, I initiate an object: export class fullData { AProp : any; BProp : any; CProp : any; } …
Guy E
  • 1,775
  • 2
  • 27
  • 55
3
votes
3 answers

merge two Map Values in Java and if key is same append the Values not overwrite in Java 7 or Java 8

I want to merge 2 Maps, but when the key is the same, the values should be appended instead of overwritten. Let's say Map> map1 = new HashMap<>(); Set set1 = new…
Arjun
  • 45
  • 2
  • 11
2
votes
1 answer

Argument of type is not assignable to type ObservableInput

How to fix an issue where argument of type (key:string) => Observable | PayloadType | is not assignable to parameter of type '(value: string, index: number) => ObersvableInput' return action$.pipe( filter(a => a.type === 'ACTION'), …
2
votes
1 answer

How to unit test chained requests with mergeMap

How can I unit test the mergeMap in chained requests like the one in the following service: import { Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { mergeMap, delay } from…
2
votes
2 answers

Catching errors in rxjs with mergeMap operator

I've written a code in which I would like to catch an error when exception occurs: this.assetApiService.getAssets(new AssetSearchCriteriaDto({tags: [AssetTags.tenant]})).pipe( catchError(error => { console.log(error); …
Krzysztof Michalski
  • 791
  • 1
  • 9
  • 25
2
votes
1 answer

How to merge results in angular fire from array from references

I have a array of references retrieved from angularfire this.userIds$ = this.users$.switchMap(email => db.list('/USERS/', ref => { let temp = email ? ref.orderByChild('EMAIL').startAt(email).endAt(email + "\uf8ff") : ref …
Dazza
  • 145
  • 1
  • 10
2
votes
2 answers

How to limit mergeMap inner subscriptions to the N latest or a sliding window queue

I have a source stream merged from two streams. When the source stream emit event I'd like to call a subscription function Meteor.subscribe and keep it open, so I use mergeMap. When subscription is ready I pipe to another mergeMap to populate the…
Andrey Kartashov
  • 1,368
  • 1
  • 12
  • 20
1
vote
1 answer

How to handle condition inside mergeMap?

Obs1$.pipe( mergeMap((data) => { if (data.condition) { const generatedStuff = doSomethingFunction(data1); return generatedStuff.Obs2$; } someCleanupAction(); return of(null); // I want to get rid this because I don't…
Anutrix
  • 145
  • 1
  • 9
1
vote
2 answers

Run Multiple HTTP Requests One After Another and Return Observable

I have two observable request functions below and although it works, I need the fire print to run after the newOrder api and return the observable. I tried using mergeMap but it just skipped through without providing any error. postNewOrder(id:…
z123
  • 193
  • 1
  • 15
1
vote
1 answer

Mergemap - More Than 2 Observables

I got a service method working that would get all of the items from a collection, and merge in user data from a different user collection so that it could easily be displayed on the front end. I tried to add a third layer of observables to pull and…
1
vote
3 answers

Angular data undefined outside subscribe

I know it was asked million times, but i really don't understand how it works. I tried to new Promise, but there is nothing inside then() i tried to do it with mergeMap but messed up. I want to get current user's favorite items. And to do it i'm…
1
2 3 4