[RxJS] exhaustMap vs switchMap vs concatMap
exhaustMap: It drop the outter observable, just return the inner observable, and it waits until previous observable complete before emit next observable.
Good for canceling extra network outter request, for example click (outter) request trigger network (inner) request, if network (inner) request is not finished yet, new click (outter) request will be ignored.
Use case: "Save" button, avoid send extra network request to the server.
switchMap: Map to inner observable, cancel previous request.
// exhaustMap @Effect()
login$ = this.actions$
.ofType(Auth.LOGIN)
.map((action: Auth.Login) => action.payload)
.exhaustMap((auth: Authenticate) =>
this.authService
.loginUser(auth.email, auth.password))
.map(user => new Auth.LoginSuccess({user}))
.catch(error => of(new Auth.LoginFailure(error))); // switchMap @Effect()
login$ = this.actions$
.ofType(Auth.LOGIN)
.map((action: Auth.Login) => action.payload)
.switchMap((auth: Authenticate) =>
this.authService
.loginUser(auth.email, auth.password)
.map(user => new Auth.LoginSuccess({user}))
.catch(error => of(new Auth.LoginFailure(error)));
)
.shareReplay(1)
SwitchMap has cancelling logic.
concatMap:
Good for waiting previous network request finished. For example, We have a form, when use is typing, we also want to save the data, send to the server.
Every network request will send in order, and wait pervious network request finished.
[RxJS] exhaustMap vs switchMap vs concatMap的更多相关文章
- RxJS中高阶操作符的全面讲解:switchMap,mergeMap,concatMap,exhaustMap
RxJS中高阶映射操作符的全面讲解:switchMap, mergeMap, concatMap (and exhaustMap) 原文链接:https://blog.angular-universi ...
- [RxJS] Use RxJS concatMap to map and concat high order observables
Like switchMap and mergeMap, concatMap is a shortcut for map() followed by a concatAll(). In this le ...
- angular2 学习笔记 ( rxjs 流 )
RxJS 博大精深,看了好几篇文章都没有明白. 范围牵扯到了函数响应式开发去了... 我对函数式一知半解, 响应式更是第一次听到... 唉...不过日子还是得过...混着过先呗 我目前所理解的很浅, ...
- RxJS——Operators
RxJS 的操作符(operators)是最有用的,尽管 Observable 是最基本的.操作符最基本的部分(pieces)就是以申明的方式允许复杂的异步代码组合简化. 什么是操作符? 操作符是函数 ...
- rxjs简单入门
rxjs全名Reactive Extensions for JavaScript,Javascript的响应式扩展, 响应式的思路是把随时间不断变化的数据.状态.事件等等转成可被观察的序列(Obser ...
- RxJS v6 学习指南
为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...
- RxJS速成 (下)
上一部分: http://www.cnblogs.com/cgzl/p/8641738.html Subject Subject比较特殊, 它即是Observable又是Observer. 作为Obs ...
- ReactiveX 学习笔记(30)操作符辨析
RxJava: merge/concat/switch RxJS: merge/concat/switch/exhaust RxSwift: merge/concat/switchLatest mer ...
- Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数
上一篇:Angular2入门系列教程5-路由(一)-使用简单的路由并在在路由中传递参数 之前介绍了简单的路由以及传参,这篇文章我们将要学习复杂一些的路由以及传递其他附加参数.一个好的路由系统可以使我们 ...
随机推荐
- javascript中for...in和for...of的区别
for...of循环是ES6引入的新的语法. for...in遍历拿到的x是键(下标).而for...of遍历拿到的x是值,但在对象中会提示不是一个迭代器报错.例子如下: let x; let a = ...
- NS2学习笔记(五)
对无线网络,生成nam文件要使用namtrace-all-wireless, 而不是namtrace-all: set nf [open test_1.nam w] $ns_ namtrace-all ...
- win快速搜索软件
Everything 与其他搜索工具的简单比较: Everything 是至今为止 X-Force 所使用过速度最快的文件搜索工具.与它相似的有异次元曾经介绍过一款很老的软件AVAFind,也非常的优 ...
- python自动化测试学习笔记-6redis应用
上次我们学到了redis的一些操作,下面来实际运用以下. 这里我们先来学习一下什么是cookie和session. 什么是Cookie 其实简单的说就是当用户通过http协议访问一个服务器的时候,这个 ...
- jmeter中beanshell断言的使用
简单使用beanshell的内容,进行测试内容的判断 这里通过断言内容,修改if的条件,达到发送警报邮件的功能 beanshell 代码如下: SampleResult 等效于 prev lo ...
- BZOJ 4481
思路: 等比数列求和 (无穷项) +线段树找逆序对 //By SiriusRen #include <bits/stdc++.h> ; ; ],ans; struct Node{int x ...
- 题解报告:hdu 2149 Public Sale(巴什博弈)
题目链接:acm.hdu.edu.cn/showproblem.php?pid=2149 Problem Description 虽然不想,但是现实总归是现实,Lele始终没有逃过退学的命运,因为他没 ...
- Excel工作常用(一)-生成序列与删除空行
整理一些工作中,本人经常用到的一些Excel操作 1.自动生成序列 [注]选择 第一格 和 第二格 之后,在右下角出现十字的时候,在往下拉 2.删除空行 方式一,先找出所有空行,在删 [缺点]数据多的 ...
- Alpha Edition [ Group 1 ]
Deltafish Alpha Edition 一.博客归档(记录人:娄雨禛) 小组会议 DeltaFish 校园物资共享平台 第一次小组会议 DeltaFish 校园物资共享平台 第二次小组会议 D ...
- Pycharm:debug调试时使用参数
一种操作方法: 文章链接:MAC下使用Pycharm,debug调试时怎样带参数 今天在网上找了一个例子敲代码,因为我使用的是PyCharm,例子运行时需要带参数,开始不知道怎么带参数,网上搜了大半天 ...