RxJS mergeMap 学习笔记
https://www.learnrxjs.io/learn-rxjs/operators/transformation/mergemap
This operator is best used when you wish to flatten an inner observable but want to manually control the number of inner subscriptions.
使用场合:当您希望展平内部 observable 但想要手动控制内部订阅的数量时
For instance, when using switchMap each inner subscription is completed when the source emits, allowing only one active inner subscription. In contrast, mergeMap allows for multiple inner subscriptions to be active at a time. Because of this, one of the most common use-case for mergeMap is requests that should not be canceled, think writes rather than reads. Note that if order must be maintained concatMap is a better option.
例如,当使用 switchMap 时,每个内部订阅在源发出时完成,只允许一个活动的内部订阅。 相比之下,mergeMap 允许同时激活多个内部订阅。 因此,mergeMap 最常见的用例之一是不应取消的请求,认为是写入而不是读取。 请注意,如果必须维护顺序,则 concatMap 是更好的选择。
注意内存泄漏问题。
Be aware that because mergeMap maintains multiple active inner subscriptions at once it’s possible to create a memory leak through long-lived inner subscriptions. A basic example would be if you were mapping to an observable with an inner timer, or a stream of dom events. In these cases, if you still wish to utilize mergeMap you may want to take advantage of another operator to manage the completion of the inner subscription, think take or takeUntil. You can also limit the number of active inner subscriptions at a time with the concurrent parameter
由于 mergeMap 一次维护多个活动的内部订阅,因此可能会通过长期存在的内部订阅造成内存泄漏。 一个基本示例是,如果您要映射到具有内部计时器的 observable 或 dom 事件流。 在这些情况下,如果您仍然希望使用 mergeMap,您可能希望利用另一个操作符来管理内部订阅的完成,考虑 take 或 takeUntil。 您还可以使用 concurrent 参数限制一次活动内部订阅的数量。
相关文章
- .net Elasticsearch 学习入门笔记
- 《Head First Servlet JSP》学习笔记一
- Ninject学习笔记<四>
- mysql--SQL编程(关于mysql中的日期) 学习笔记2
- 机器学习笔记 - 什么是标准正态分布表?
- 机器学习笔记 - Kaggle表格游乐场 Mar 2022 学习一
- 数学建模学习笔记(十八)SIER模型灵敏度分析(matlab求解)
- xpath路径表达式笔记
- MIME笔记
- Javascript 学习 笔记二
- Rxjs 的一些学习笔记
- 【vuejs】1/5vue 学习笔记
- JavaScript学习笔记之JavaScript调用C#编写的COM组件
- SpringBoot学习笔记(七)——综合示例BookStore图书管理系统
- dojo 学习笔记之dojo.query - query(id) 与query(class)的差别
- c++函数式编程 笔记
- Python学习笔记24:Django搭建简单的博客站点(二)
- Web Service学习笔记
- 802.11 学习笔记
- MATLAB学习笔记(六)——MATLAB数据分析与多项式计算
- 数学建模笔记总结
- Scala学习笔记总结
- C/C++学习笔记 各种字符转换记录
- 内存一些小笔记