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的更多相关文章

  1. RxJS中高阶操作符的全面讲解:switchMap,mergeMap,concatMap,exhaustMap

    RxJS中高阶映射操作符的全面讲解:switchMap, mergeMap, concatMap (and exhaustMap) 原文链接:https://blog.angular-universi ...

  2. [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 ...

  3. angular2 学习笔记 ( rxjs 流 )

    RxJS 博大精深,看了好几篇文章都没有明白. 范围牵扯到了函数响应式开发去了... 我对函数式一知半解, 响应式更是第一次听到... 唉...不过日子还是得过...混着过先呗 我目前所理解的很浅,  ...

  4. RxJS——Operators

    RxJS 的操作符(operators)是最有用的,尽管 Observable 是最基本的.操作符最基本的部分(pieces)就是以申明的方式允许复杂的异步代码组合简化. 什么是操作符? 操作符是函数 ...

  5. rxjs简单入门

    rxjs全名Reactive Extensions for JavaScript,Javascript的响应式扩展, 响应式的思路是把随时间不断变化的数据.状态.事件等等转成可被观察的序列(Obser ...

  6. RxJS v6 学习指南

    为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...

  7. RxJS速成 (下)

    上一部分: http://www.cnblogs.com/cgzl/p/8641738.html Subject Subject比较特殊, 它即是Observable又是Observer. 作为Obs ...

  8. ReactiveX 学习笔记(30)操作符辨析

    RxJava: merge/concat/switch RxJS: merge/concat/switch/exhaust RxSwift: merge/concat/switchLatest mer ...

  9. Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数

    上一篇:Angular2入门系列教程5-路由(一)-使用简单的路由并在在路由中传递参数 之前介绍了简单的路由以及传参,这篇文章我们将要学习复杂一些的路由以及传递其他附加参数.一个好的路由系统可以使我们 ...

随机推荐

  1. CyclibcBarrier与CountDownLatch区别

    1.CyclibcBarrier的线程运行到某个位置后即停止运行,直到所有的线程都到达这个点,所有线程才开始运行:CountDownLatch是线程运行到某个点后,计数器-1,程序继续运行即Cycli ...

  2. BZOJ 4140 凸包+二进制分组

    思路: $(x_0-x)^2+(y_0-y)^2<=x^2+y^2$ $y>=(-x_0/y_0)x+(x_0^2+y_0^2)/2y0$ 这显然就是凸包了 以一个斜率不断向下(上)走   ...

  3. what is success?

    什么是成功?这是个老话题了.然而每个人对成功的认识却也不同.记得央视主持人王志说过成功是相对的,每个人都有自己的成功标准.有的人认为有钱.有房.有车.有女人,就是成功.有的人则认为成功是你做了一件你想 ...

  4. MVC系列学习(十五)-验证码

    1.方式一: public class VCode { /// <summary> /// 生成验证码图片 字节数组 /// </summary> /// <return ...

  5. C#学习-程序集和反射

    准备项目 1.新建一个空的解决方案MyProj.sln 2.在该解决方案下,建一个控制台项目P01.csproj 3.在该项目下,自己新建一个类MyFirstClass.cs 查看解决方案MyProj ...

  6. 字符串String的理解

    1.String是一个final的类型 即不可被继承修改,一经生成不可改变.所以在代码中使用String s  = s1 + s2;的时候,执行完之后s所指向的是一个新生成的对象,这里有个地方值得注意 ...

  7. wordpress登录账号之后才能查看页面,实例

    函数: <?php auth_redirect(); ?> 例子: 要求用户登录才能查看页面 if(!is_user_logged_in()){ auth_redirect(); } 源文 ...

  8. Android项目实战_手机安全卫士进程管理

    ###1.设备进程信息获取获取设备运行进程 ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVI ...

  9. css3背景渐变色代码

    从上到下 #grad {  background: -webkit-linear-gradient(red, blue);  background: -o-linear-gradient(red, b ...

  10. JS——正则案例

    验证座机号码 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT ...