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
3
votes
1 answer

Which is a better way to combine multiple LiveData(s): using MediatorLiveData or switchMap?

Which approach is more recommended to combine multiple LiveData(s): using MediatorLiveData or switchMap? // MediatorLiveData approach fun combine( liveData1: LiveData, liveData2: LiveData, onChanged: (A?, B?) -> C ):…
3
votes
2 answers

Angular 9/rxjs: How to handle an error thrown inside switchMap?

I'm using Angular (9) powered Bootstrap (6.1.0) TypeAhead and defining its search function like so: search = (text$: Observable) => { return text$.pipe( debounceTime(200), distinctUntilChanged(), // switchMap allows…
CAK2
  • 1,892
  • 1
  • 15
  • 17
3
votes
2 answers

switchMap distincted by property in RxJs

Let's say, I have a stream of actions. Each action is assigned some id. Like this: const actions$ = of({ id: 1 }, { id: 2 }, { id: 1 }); Now, for each action, I want to perform some logic in switchMap: actions$.pipe(switchMap(a => /* some…
cezn
  • 2,705
  • 11
  • 16
3
votes
2 answers

Question is : Property 'switchMap' does not exist on type 'Observable

I have this problem when trying to run in git bash. .switchMap is not geting executed and showing error as" error TS2339: Property 'switchMap' does not exist on type 'Observable' " The code I am using is: import { User } from…
subhajit biswas
  • 261
  • 2
  • 6
3
votes
1 answer

RxJS switchMap and passing response to another operator

Let say I have code like that: this.apiService.getUrlForPhoto('photo1') .switchMap((url) => { return this.apiService.uploadPhotoToProvidedUrl(url); }) .switchMap((response) => { …
Adam Adamski
  • 737
  • 3
  • 11
  • 20
3
votes
1 answer

SwitchMap not working as intended in Angular

I have a search service returning results, if the user submits twice, only the last search should return results. I have the following code in a service, view (updated elsewhere) has all the post body info needed for the request. This method is…
Ben Taliadoros
  • 7,003
  • 15
  • 60
  • 97
3
votes
0 answers

RxJS switchMap does not cancel inner merged observable

The inner merged observable isn't terminating with this code (rxjs 5.5.6): let source = new Subject(); // when the source emits a vector of strings, output // each string with a 1s delay source.switchMap(v =>…
kayjtea
  • 2,979
  • 1
  • 20
  • 19
2
votes
1 answer

Understanding Marble diagram for switchmap

This is the marble diagram for a RxJs swithmap function. Reference: https://rxjs.dev/api/operators/switchMap My questions are: What is the large space between 1 & 3 and small space between 3 & 5 mean? Is it duration in seconds between those numbers…
wonderful world
  • 10,969
  • 20
  • 97
  • 194
2
votes
1 answer

switchMap gives OperatorFunction' is not assignable

I need to switch a stream to an other stream, so I did this.appState.domain$.pipe(switchMap(() => of(10)) It gives me an error OperatorFunction' is not assignable to parameter of type OperatorFunction' .... For me,…
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
2
votes
2 answers

Why does my http request cancel/stop observables stream?

I have an array of applications and I want each application to have a new property called Blobs. I have to make a new HTTP request to get Blobs for every single application and I use switchMap for that. However, for some reason, it only emits the…
Vazhaabdu
  • 23
  • 3
2
votes
2 answers

Launching a coroutine within a switchmap

So I'm writing an app that displays a list of movies. I want to implement a search functionality where the function to display the search results will be called from the api. However, I'm having trouble implementing the switchmap within the…
2
votes
3 answers

rxjs: access the result of original observable after it was switchMap'ped

How do I access the resultB in the tap operator after it was switchMapped ? streamA$.pipe( switchMap(resultA => { const streamB$ = resultA ? streamB1$ : streamB2$; return streamB$.pipe( // <- nesting …
eagor
  • 9,150
  • 8
  • 47
  • 50
2
votes
2 answers

How to finilize rxjs switchmap observable?

I have an observable in my angular 8 project, and subscribing in ngOnInit(). export class ChartComponent implements OnInit { urlSubject: Subject = new Subject(); isLoading: BehaviorSubject = new…
barteloma
  • 6,403
  • 14
  • 79
  • 173
2
votes
1 answer

Is there, in kotlin and android, something similar to switchmap in rxjs or rxjava?

I want to find out is there something similar to switchmap in kotlin and android (LiveData maybe). I need to change my request immediately after events that can happen very often and which determine what to request from the server, respectively, I…
Roab
  • 393
  • 3
  • 7
2
votes
1 answer

Why can't I access property when using switchMap?

I have a method attached to a button. A user enters their name in an input, and when the button is clicked, information from that user is displayed. How I am planning to do that is explained below.. I am trying to pass in a value from one…
babinec
  • 91
  • 9
1
2
3
12 13