All of the combination operators take two or more observables as input. These operators may also be alternatively called "vertical combination operators", because of how they work in a marble diagram. Next, we will learn about scan(), which is an important "horizontal combination operator".

var click$ = Rx.Observable.fromEvent(document.querySelector("#btn"), 'click');

/*

----ev-----ev---ev----ev----ev----..
mapTo(1)
----1 -----1 ---1 ----1 ----1-----..
scan( (acc, curr) => acc + curr, 0)
----1------2----3-----4-----5-----.. */ var clicks$ = click$
.mapTo(1)
.scan( (acc, curr) => {
return acc + curr
}, 0); var sub = clicks$.subscribe(
(x) => console.debug("Total Clicks: " + x),
(err) => console.error(err),
() => console.info("DONE")
)
var foo$ = Rx.Observable.of('h', 'e', 'l', 'l', 'o')
.zip(Rx.Observable.interval(500), (c, t) => c); var bar$ = foo$.scan( (acc, curr) => {
return acc + curr;
}, ''); /* -----h-----e-----l-----l------o| (foo)
scan( (acc, curr) => acc + curr, '')
-----h-----(he)--(hel)-(hell)-(hello|) (bar) */ var sub = bar$.subscribe(
(x) => console.debug(x),
(err) => console.error(err),
() => console.info("DONE")
);
/** "h"
"he"
"hel"
"hell"
"hello"
"DONE"
*/

[RxJS] Transformation operator: scan的更多相关文章

  1. [RxJS] Transformation operator: repeat

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

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

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

  3. [RxJS] Transformation operator: map and mapTo

    We made our first operator called multiplyBy, which looks a bit useful, but in practice we don't nee ...

  4. [RxJS] Transformation operator: bufferToggle, bufferWhen

    bufferToggle(open: Observable, () => close: Observalbe : Observalbe<T[]>) bufferToggle take ...

  5. [RxJS] Utility operator: do

    We just saw map which is a transformation operator. There are a couple of categories of operators, s ...

  6. rxjs自定义operator

    rxjs自定义operator

  7. [RxJS] Creation operator: of()

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

  8. [RxJS] Connection operator: multicast and connect

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

  9. [RxJS] Combination operator: withLatestFrom

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

随机推荐

  1. jquery 属性与css操作

    属性1.属性    1.1 attr(name|properties|key,value|key,fn)        1) 获取属性值    $("img").attr(&quo ...

  2. ext 金额大写

    //数字转换成大写金额函数 function atoc(numberValue) { numberValue = numberValue.replace(/,/g,''); numberValue = ...

  3. 利用def生成dll文件

    DLL中导出函数的声明有两种方式:一种为在函数声明中加上__declspec(dllexport),这里不再举例说明:另外一种方式是采用模块定义(.def) 文件声明,.def文件为链接器提供了有关被 ...

  4. 知识管理(knowledge Management)2

    ①找到生命的主轴 ②跨领域知识管理

  5. 简单python2.7.3安装setuptools模块

    下载setuptools https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg 安装 .6c11- ...

  6. Sharepoint 问题集锦 - 外部列表(external list) - 读取当前用户上下文或用户名作为筛选参数

    在创建外部列表过程中,往往需要添加筛选参数,而较多开发用户,会关心如何在外部列表中,只显示当前用户相关的行.本例子中,我们以任务数据表来做例子,看看如何实现这个需求. 1)数据表tbl_task: t ...

  7. Java客户端协议处理框架简介

    无论FTP客户程序,还是HTTP客户程序,或是其他基于特定应用层协议的客户程序,在与远程服务器通信时,都需要建立与远程服务器的连接,然后发送和接收与协议相符的数据.客户程序还需要对服务器发送的数据进行 ...

  8. iOS:等待控件

    定义: @interface ViewController () { UIActivityIndicatorView *testActivityIndicator; } 实例化,开始旋转: -(voi ...

  9. python 文件及文件夹操作

    python 文件.目录操作(新增.移动.删除等) python 文件夹与文件操作 mport string, os, sys dir = '/var' print '----------- no s ...

  10. 总结Web应用中基于浏览器的安全漏洞

    ‍‍‍‍‍1.浏览器缓存 每次打开一个网站,网页的内容会缓存到用户的机器中.如果这些内容在其他网页中需要重新加载,浏览器加载的是缓存,而不是再次下载内容.如果一些Web应用商店以及显示用户敏感信息(比 ...