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

rxjs switchMap cache the obsolete result and do not create new stream

const s1$ = of(Math.random()) const s2$ = ajax.getJSON(`https://api.github.com/users?per_page=5`) const s3$ = from(fetch(`https://api.github.com/users?per_page=5`)) const click$ = fromEvent(document, 'click') click$.pipe( switchMap(() =>…
Guichi
  • 2,150
  • 1
  • 19
  • 27
0
votes
2 answers

switchMap Strange Behavior

I am trying to understand the following code's console output. I was expecting it will console log 0 through 9 every 500ms and then start over with 0 again (and end up with 9). But the fact is it would only console log 0-9 the very first time, and…
HFrost
  • 67
  • 4
0
votes
1 answer

(Angular 2/4/5/6) Two (or more) inner subscribe methods and one outer subscribe method

I'm trying to figure out how do I call 2 inner subscribe methods with an outer subscribe method. In total I would like to do 3 api calls, however, 2 api calls are dependent on the results of 1 api call. this.subscription = this.quoteService //1st…
iBlehhz
  • 566
  • 5
  • 26
0
votes
1 answer

Trying to figure out how to switchMap an Organization to a Base in an Angular Component

So I have an API that I am trying to consume data from. The data being retuned: Org baseId: 1 createdAt: "2018-11-14T04:35:35.345Z" id: 1 isActive: true orgName: "Test Organization 1" orgOwner: 2 subscriptionCode: "testorg1" updatedAt:…
Clayton Allen
  • 239
  • 3
  • 15
0
votes
2 answers

How to subscribe to an observable from a function that returns observable?

So I have a put method that returns an observable, inside this method I need to check if the token is valid, if it is not valid, then I will need to call another method that can create a new refresh token and I need to subscribe to this method so…
Wael
  • 1,533
  • 4
  • 20
  • 35
0
votes
0 answers

Ngrx/ effects passing null value on SwitchMap

The tasks this code is trying to accomplish are these in order Im trying to listen for an action take the payload for that action pass that payload to a database service function pass the payload to a success reducer action The data is supposed…
Siddartha
  • 175
  • 1
  • 8
0
votes
1 answer

Calling subscribe inside subscribe

There are two variables depending on each other (color and pictures). Depending means following: When the variable color has the value of'BLUE' I want to filter all the pictues which have the color blue and so on. Variable pictures is a subject…
myanmar
  • 81
  • 1
  • 2
  • 11
0
votes
0 answers

rxjs: how can I get informed of an unsubscription of an observable

I have an Angular project where HTTP-searches are started by typing in an input field. This is done like the examples on the web with following code (simplified): this.form.valueChanges.pipe ( debounceTime (this.dueTime), distinctUntilChanged…
Galdor
  • 1,636
  • 4
  • 23
  • 37
0
votes
0 answers

Transformations.switchMap Function not called in ViewModel

I am observer LiveData from Repository and transform to view,here Transformations.switchMap Function not called in ViewModel. If I use observeForEver it works good. Transformations.switchMap(signInResponseMutableLiveData){signInResponse -> …
Ramprasad
  • 7,981
  • 20
  • 74
  • 135
0
votes
1 answer

Type 'Observable<(T | R[])[]>' is not assignable to type 'Observable<[T, R[]]>

I am trying to map data from two observables to a third one like return this.coursesService .findCourseByUrl(route.params['id']) .pipe( switchMap((course: Course) => this.coursesService .findLessonsForCourse(course.id) …
Vijender Kumar
  • 1,285
  • 2
  • 17
  • 26
0
votes
1 answer

Use switchMap with Kedno UI Gid in Angular2+

I use Kendo UI for Angular Grid with data binding. I have two services: one to emit search event from filter component to grid component and one (based on BehaviorSubject) to call API. The way of data binding with Grid that I use is based on…
0
votes
1 answer

How to use param from one stream in another with RX.js?

If I want to pass returned value from the first stream to second I use switchMap . What should I use, if I want to use param from the first stream in second, but I don't want to do 2 subscribe? this.firstStream$.subscribe(first => { …
John Doe
  • 3,794
  • 9
  • 40
  • 72
0
votes
1 answer

RxJs and switchMap

i want create search engine in my website. I want to use switchMap to cancel previous request, because this function run async. I getting data from input by keyup, example:
Wojtar
  • 35
  • 3
0
votes
2 answers

Cancellable chain of requests

So, I'm trying to wrap my head around rxjs/observable, in my test-case study I'm trying to build a simple angular(5) based web-app that should display some stats about geo entities, namely country, state, city. So I've crated changeView method that…
Jyrkka
  • 526
  • 1
  • 8
  • 26
0
votes
1 answer

Result from ActiveRoute needed for two independent succeeding queries

What is the best practice when I need to use switchMap on an Observable twice (independent queries). I need the Id returned from activeRoute.ParamMap... for two independent queries. For only one query, I would do the…
1 2 3
12
13