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.
Very interesting when click twice, it will cancel the first fetch process. But how does it happy exactly?
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.