The use case is similar to Twitter "like" button, you can click "click" button on different post, each "like" button are isolated, it preforms optimistic UI render, handling the back-press on backend, cancel previous request only for the same twitter id.

In the talk of RxJS. It use Movie as example.

So, if you have similar use case, this piece of code can help:

import { Observable, fromEvent, Subject, EMPTY } from 'rxjs';
import { tap, mergeMap, groupBy, timeoutWith, ignoreElements, switchMap } from 'rxjs/operators'; const actions$ = dispatcher.asObservable().pipe(
// optimize ui rendering
tap(({ movieId }) => setButtonEmoji(movieId)),
// group all the request by movieId
groupBy(
movie => movie.movieId,
movie => movie,
// cancel the extra requests to prevent memory leak by set 15s idel time
actionsByGroup$ =>
actionsByGroup$.pipe(
timeoutWith(, EMPTY),
ignoreElements()
)
),
// for each group of request, we apply switchMap to cancel previous request
// finally flatten the requests into one
mergeMap(group$ => group$.pipe(switchMap(movie => toggleStatus(movie.movieId))))
);

最新文章

  1. spring笔记--依赖注入之针对不同类型变量的几种注入方式
  2. 第一次接触servlet的知识
  3. ffmpeg-20160731-bin.7z
  4. AngularJs 简单实现全选,多选操作
  5. ANGULARJS 动态编译添加到dom中
  6. checkbox 赋值给js 变量
  7. Linux安装MySQL的两种方法
  8. ZOJ 2677 Oil Deal(最大生成树)
  9. 【转】 Android——eclipse共享library以及导出jar包
  10. 老李分享:大数据测试之HDFS文件系统
  11. NYOJ 2357: 插塔憋憋乐 贪心
  12. windows下编译Grafana前端
  13. phpcms 标签含义大全
  14. 004_zookeeper运维之maxClientCnxns overflow
  15. 在网站中使用UEditor富文本编辑器
  16. ThreadLocal源码实现。
  17. windows 常用dos命令
  18. js如何用json 读取C#的Dictionary
  19. leetCode练习题
  20. flask request模块

热门文章

  1. 使用无图形界面启动Centos
  2. Spring Boot(二)
  3. Java 处理异常
  4. 【洛谷 P3674】 小清新人渣的本愿(bitset,莫队)
  5. Django:母版、继承、组件、自定义标签
  6. 记支付宝接口对接,涉及到提取证书SN号的解决方案
  7. 【代码片段】定时记录CPU使用率并保存为CSV
  8. 挂载nfs提示:mount.nfs: access denied by server while mounting...
  9. net 与或非
  10. 反射,内置方法,__str__ __repr__