Questions tagged [switchmap]

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

switchMap is an RxJS flattening operator to handle observables and emit values. Used in coding reactive web pages.

This operation works well to handle observables, where there is no need to ensure that the call has succeeded, only returning the value from the latest call.

Related tags:

195 questions
1
vote
1 answer

Emitting a hot boolean observable using switchMap?

Trying to create an isEmpty:Observablemethod that emits a hot Observable using a switchMap. This is what I have so far: /** * Notifies observers when the store is empty. */ protected notifyOnEmpty = new…
Ole
  • 41,793
  • 59
  • 191
  • 359
1
vote
2 answers

Does switchMap to Angular HTTP-Request needs unsubscribe

I am wondering if I have to unsubscribe my subscription in the following case. I create an observable using combineLatest of the two angular observables route.params and route.queryParams. To use them as parameters within an http request I call…
Pascal Chorus
  • 360
  • 4
  • 12
1
vote
1 answer

Argument of type '(num: number) => void' is not assignable to parameter of type '(value: number, index: number) => ObservableInput<{}>'

I have some question about rxjs function. Actually, I make a request to http server. The way I receive data from http server is two steps because each request returns only 10 items, not entire items. Each request has page number so, if I have a…
Anna Lee
  • 909
  • 1
  • 17
  • 37
1
vote
1 answer

How to rewrite this @effect for api delete call returning no entity?

The problem is that api.deleteUser returns null (status 204), so the user is lost. How to pass the user (which is action.payload) to DeleteUserSuccess(user)? @Effect() public deleteUser$: Observable = this._actions$ …
Ekaterina
  • 1,642
  • 3
  • 19
  • 36
0
votes
1 answer

testing switchMap in component in Angular

I have a component method with this format: action(): Observable { return this.service.actiontaken(this.ids).pipe( switchMap(() => { return this.otherMethod(this.ids); }), ); } I am able to test the part upto…
Aastha Bist
  • 324
  • 2
  • 11
0
votes
0 answers

How to cancel a previous HTTP call using switchMap without a source observable?

I've been trying to think of a good way to cancel previous HTTP request when new requests are fired, for which I would normally use the switchMap operator. However, due to my request being not bound to a button click or any other event, but is…
0
votes
2 answers

Angular: check an observable that may return null inside switchmap

how to handle the nullity case within a switchmap operator ? I found this workaround, but I get the impression it’s not great to do this: this.userService .getApporteurId() .pipe( switchMap((test) => test ?…
Olivier
  • 343
  • 2
  • 16
0
votes
1 answer

How to: Rxjs Observable Process values in order (concatMap), handling errors(catchError), without 'stopping' (switchmap)

Goal: Process(async Call) all elements from Observable in order, finishing one before the next (concatMap style) while handling errors from bad elements without stopping. It is understood that an observable that errors, will stop its emissions As…
redevill
  • 341
  • 1
  • 3
  • 9
0
votes
1 answer

Unexpected output with delayed Observable when subscribing right after `next`ing

Let's look at this piece of code: let isNull = true; const a$ = new Subject(); const b$ = a$.pipe( switchMap(() => { if (!isNull) return of(true).pipe( tap(() => console.log('should be shared')), delay(100) // (3) …
Szymon
  • 51
  • 1
  • 6
0
votes
1 answer

Is there a way to indicate when the RxJS operator "switchMap" discards a previous emitted item by the source Observable?

I am using an "in progress" indicator that is displayed as long as tasks are currently running. When starting a task, the tasks counter increases by 1 and decreases by 1 at the end of the task. Basically: if (count>0) displayIndicator(). When a new…
Wilhelm Mauch
  • 23
  • 1
  • 6
0
votes
0 answers

Correct use of SwitchMap for chained observables in Angular 13 an RxJs 7.4

I need to chain Observables, so after one is done then do next one. And i really want to do it right. I know there are more than one ways of doing this. And from what i have red switchMap() shout work fine for me. But is it ok to set variables in…
Jackie
  • 327
  • 2
  • 13
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

Multiple nested observable with SwitchMap

In my scenario, I have an higher order observable which when emits we needs to fetch two different pieces of data as inner observables. something like $someDetails.pipe( switchMap(sd => { this.name = sd.name; let innerObservableOne =…
tangokhi
  • 945
  • 2
  • 8
  • 20
0
votes
0 answers

RXJS switchMap understanding

I am trying to use switchMap in rxjs to only emit the most recent observable and only once(the other observables should be cancelled). The goal to use this with the debounce operator, this is my start point. Now trying to make it so if I click the…
Nevaden
  • 1
  • 2
0
votes
1 answer

RxJS: Modification a previous value further down the pipe chain

In my project, I came across an intriguing case of executing several requests in a pipe chain. It's all about displaying images in the quill text editor. backend returns content in the form: content: "alt.png
Gnarmoni
  • 5
  • 1