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))))
);

[RxJS] Groupby operator的更多相关文章

  1. rxjs自定义operator

    rxjs自定义operator

  2. [RxJS] Creation operator: of()

    RxJS is a lot about the so-called "operators". We will learn most of the important operato ...

  3. [RxJS] Connection operator: multicast and connect

    We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...

  4. [RxJS] Transformation operator: repeat

    Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...

  5. [RxJS] Transformation operator: buffer, bufferCount, bufferTime

    This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...

  6. [RxJS] Transformation operator: scan

    All of the combination operators take two or more observables as input. These operators may also be ...

  7. [RxJS] Combination operator: withLatestFrom

    Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...

  8. [RxJS] Combination operator: combineLatest

    While merge is an OR-style combination operator, combineLatest is an AND-style combination operator. ...

  9. [RxJS] Filtering operator: filter

    This lesson introduces filter: an operator that allows us to let only certain events pass, while ign ...

随机推荐

  1. Docker创建镜像 并推拉Harbor

    创建镜像 一.根据dockerfile创建镜像 文件详解 1.mkdir dockerfile/lib/centos7base/ 创建目录 2.创建Dockerfile vim Dockerfile ...

  2. UML概念模型

    UML概念模型 UML(Unified Modeling Language):统一建模语言,为面向对象开发系统的产品进行说明.可视化.和编制文档的标准语言 面向对象程序设计 面向对象基本概念:对象.类 ...

  3. tensorboard 拒绝访问解决方法

    打开Anaconda Prompt,切换到TensorFlow环境(activate tensorflow) 切换成功之后,输入tensorboard --logdir='路径' 注意:--logdi ...

  4. 数组,const,#define

    #include<stdio.h> #define COUNT 6 int main(){// const类型的常量不能作为数组的个数,大部分编译器不支持//    const int C ...

  5. [洛谷P5329][SNOI2019]字符串

    题目大意:给一个长度为$n$的字符串$s$,字符串$p_i$为字符串$s$去掉第$i$个字符后形成的字符串.请给所有字符串$p_i$排序(相同字符串按编号排序) 题解:先去掉所有连续相同字符,因为它们 ...

  6. windows10 iis浏览wcf报404.3错误

    报错:HTTP错误404.3-Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加MIME映射. 解决步骤如下: 控制面板->打开 ...

  7. 使用activiti的designer插件记录

    1.activiti添加排他网,条件下载condition中 2.activiti添加监听Listener,知道3种方法 1.实现taskListener 通过加载java class的方式去加载实现 ...

  8. 【转载】C#中List集合SingleOrDefault和FirstOrDefault方法有何不同

    在C#的List集合类的操作过程中,有时候我们会使用到List集合的SingleOrDefault方法和FirstOrDefault等方法,这2个方法都是System.Linq.Enumerable类 ...

  9. django路由的反向解析

    什么是路由的反向解析 我们的路由都是一个匹配关系,对应一个处理的视图函数, 如果我们的匹配关系发生了变化,那么与之对应的访问地址(可能前端直接url链接, 也可能是后端的redrict跳转)都需要跟着 ...

  10. UNTIY Canvas

    一.Canvas 组件 Render Mode(渲染模式) (1)Screen Space-Overlay:2D UI,始终显示在屏幕最前方,适合制作HP,MP等(相当于GUI) (2)Screen ...