[RxJS] Use RxJS concatMap to map and concat high order observables
2024-10-01 22:47:55
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.
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,
);
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
最新文章
- PCA数据降维
- 无后台的网站 内容暂存json
- java疑问-继承问题
- createjs 入门之EaselJs 绘制图片Bitmap
- leetcode-【hard】273. Integer to English Words
- PHPExcel使用体会
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解
- PostgreSQL Monitor pg_activity
- HP QC IE11不支持( win7 64位 无法安装)解决方法
- raft 一致性算法
- matlab 相关性分析
- Ubuntu命令行连接WPA/WPA2无线网线
- java.lang.IllegalArgumentException: Request header is too large
- Java 读书笔记 (七) 变量
- Git初识学习
- 后端自测必备神器-PostMan
- LeetCode - Reorganize String
- [转]小程序web-view组件
- jQuery UI dialog插件出错信息:$(this).dialog is not a function
- POJ2975:Nim(Nim博弈)