[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.
相关文章
- 在VS中让一个JS文件智能提示另一个JS文件中的成员
- Visual Studio VS如何卸载Visual assistant
- [RxJS] ShareReplay vs share
- [RxJS] Share vs ShareReply
- [VSCode] Visually Organize Applications in VS Code with Window Color-Coding
- [RxJS] exhaustMap vs switchMap vs concatMap
- [Angular 2] Angular 2 Smart Components vs Presentation Components
- vs添加对dll的引用
- [RxJS] Share vs ShareReply
- [ES6] WeakMap vs Map
- [RxJS] Stream Processing With RxJS vs Array Higher-Order Functions
- [AngularJS] ng-change vs $scope.$watch
- igbinary vs serialize vs json_encode
- Snowflake vs. Redshift的2022战报:两个数据平台谁更适合你?
- [Trading] 波动交易和日内交易的区别: Swing Trading vs. Day Trading
- SAP官方文档里关于CI和CD区别的解释:Continuous Integration vs Continuous Delivery
- atitit 高扩展性解决方案 功能扩展法 v2 t66.docx atitit 高扩展性解决方案.docx 1. 功能扩展 vs 性能扩展2 1.1. 人无远虑,必有近忧。
- Atitit.web ui 组件化 vs mvc
- atitit.html5 vs 原生 app的区别与选择
- 【codeforces 762B】USB vs. PS/2
- vs编译zlib(亲测可用)
- VS 如何在同一个解决方案下建立多个项目
- viso画图神器VS CONDE插件PlantUML
- PAT 1036 Boys vs Girls[简单]
- 【K8S系列】第七讲:有状态服务 VS 无状态服务