日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

RxJS mergeMap 学习笔记

發布時間:2023/12/19 javascript 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 參數限制一次活動內部訂閱的數量。

總結

以上是生活随笔為你收集整理的RxJS mergeMap 学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。