博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[RxJS] exhaustMap vs switchMap vs concatMap
阅读量:4562 次
发布时间:2019-06-08

本文共 1517 字,大约阅读时间需要 5 分钟。

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.

转载于:https://www.cnblogs.com/Answer1215/p/7630433.html

你可能感兴趣的文章
ssm框架的一些基本写法(纯自己总结的,如有雷同纯属巧合)
查看>>
43个优秀的Swift开源项目
查看>>
5.13Js练习题
查看>>
mysql系列之8.mysql高可用 (mha4mysql)
查看>>
DIY_DE2之DM9000A网卡调试系列例程(二)——DM9000A测试、自收发、实现UDP
查看>>
配置远程连接mysql数据库 Connect to remote mysql database
查看>>
HDU 5374 Tetris (2015年多校比赛第7场)
查看>>
《Android源代码设计模式解析与实战》读书笔记(二十二)
查看>>
Javascript
查看>>
百度之星初赛A hdu6112
查看>>
Nginx 503错误总结
查看>>
如何允许WebGL从本地载入资源
查看>>
gcc编译器局部变量在栈中的内存分配
查看>>
mapreduce中控制mapper的数量
查看>>
java海量数据处理(千万级别)(2)-海量数据FTP下载
查看>>
50个Android开发技巧(24 处理ListView数据为空的情况)
查看>>
2018-3-17-湖南多校第二场
查看>>
cocos2d CC_PROPERTY
查看>>
[原]Failed connect to mirrors.cloud.aliyuncs.com:80; Connection refused
查看>>
AOP:使用命令模式实现AOP
查看>>