The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Use RxJS switchMap to map and flatten higher order observables

Use RxJS switchMap to map and flatten higher order observables

6:04
In this lesson, we will learn about switchMap, a shortcut for mapping to a higher order RxJS Observable, then flattening with switch. We will also see a practical example with network requests that would be used in the real world.
Watch this lesson now
Avatar
egghead.io

In this lesson, we will learn about switchMap, a shortcut for mapping to a higher order RxJS Observable, then flattening with switch. We will also see a practical example with network requests that would be used in the real world.

Avatar
HaveF

Very interesting when click twice, it will cancel the first fetch process. But how does it happy exactly? fetch normally does not have cancel method( javascript - How do I cancel an HTTP fetch() request? - Stack Overflow ), and promise's cancel method is just implemented in some library like bluebird, so how it happens? Thanks for your video, Andre!

Avatar
Andre

Hi HaveF. You are right that Promises have no cancellation mechanisms. When we use them in observables, their results would simply be ignored on unsubscribe, not actually cancelled. For this reason, RxJS also has its own ajax methods that internally use XMLHttpRequest, to support cancellation. We use them like Observable.ajax('http://jsonplaceholder.typicode.com/users/1') which returns an observable of response objects.

In reply to HaveF
Avatar
HaveF

Thanks for your explanation +1

In reply to Andre
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?