[RxJS] Use RxJS concatMap to map and concat high order observables
2016-12-19 21:49
417 查看
Like switchMap and mergeMap, concatMap is a shortcut for map() followed by a concatAll(). In this lesson we will explore this RxJS operator and its properties.
concatMap happens one after the other, the same as mergeAll(1):
So the main different between switchMap, mergeMap, concatMap are about concurrency...
switchMap: has cancel previous request functionaility.
mergeMap: allows num of concurrency requests
concatMap: the same as mergeAll(1), only allow one request at a time
const clickObservable = Rx.Observable .fromEvent(document, 'click'); function performRequest() { return fetch('https://jsonplaceholder.typicode.com/users/1') .then(res => res.json()); } const emailObservable = clickObservable .concatMap(click => performRequest(), (click, res) => res.email); // concatMap = map ... + ... concatAll // mergeMap // switchMap emailObservable .subscribe(email => console.log(email));
concatMap happens one after the other, the same as mergeAll(1):
const emailObservable = clickObservable .mergeMap(click => performRequest(), (click, res) => res.email, 1);
So the main different between switchMap, mergeMap, concatMap are about concurrency...
switchMap: has cancel previous request functionaility.
mergeMap: allows num of concurrency requests
concatMap: the same as mergeAll(1), only allow one request at a time
相关文章推荐
- [RxJS] Use RxJS mergeMap to map and merge high order observables
- [rxjs] Demystifying Cold and Hot Observables in RxJS
- [Javascript + rxjs] Simple drag and drop with Observables
- [Recompose] Refactor React Render Props to Streaming Props with RxJS and Recompose
- Use data define file and colmap to map different column
- Why I can't use non-string key in the myMap[myKey] expression? And what to do now?
- [Nuxt] Use Vuex Actions to Delete Data from APIs in Nuxt and Vue.js
- Why we made vorlon.js and how to use it to debug your JavaScript remotely
- When to use next() and return next() in Node.js
- Internet Information Services is not installed. You must have Internet Information Services installed in order to use the SharePoint Products and Technologies Configuration Wizard
- [RxJS] Starting a Stream with SwitchMap & switchMapTo
- jsbin-jsfiddle-or-codepen-which-one-to-use-and-why
- [AngualrJS NG-redux] Map State and Dispatchers to Redux
- [Redux-Observable && Unit Testing] Use tests to verify updates to the Redux store (rxjs scheduler)
- [RxJS] Use takeUntil instead of manually unsubscribing from Observables
- [RxJS] Conclusion: when to use Subjects
- [RxJS] Learn How To Use RxJS 5.5 Beta 2
- [RxJS] Transformation operator: map and mapTo
- How to use $http and $resource in Angular JS
- Use C# to get JSON Data from the Web and Map it to .NET Class => Made Easy! 转