[RxJS] Transformation operator: scan
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的更多相关文章
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
- [RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...
- [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 ...
- [RxJS] Transformation operator: bufferToggle, bufferWhen
bufferToggle(open: Observable, () => close: Observalbe : Observalbe<T[]>) bufferToggle take ...
- [RxJS] Utility operator: do
We just saw map which is a transformation operator. There are a couple of categories of operators, s ...
- rxjs自定义operator
rxjs自定义operator
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- [RxJS] Connection operator: multicast and connect
We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...
- [RxJS] Combination operator: withLatestFrom
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...
随机推荐
- 11-17的学习总结(DOMfirstday)
HTML: 超文本标记语言,专门定义网页内容的语言 XHTML: 严格的HTML标准 DHTML: 所有实现网页动态效果技术的统称 XML: 可扩展的标记语言,标签都是自定义的 XML语法和HTML语 ...
- 开发语言大PK:php和Java哪个更好?
Java通过jdbc来访问数据库,通过不同的数据库厂商提供的数据库驱动方便地访问数据库.访问数据库的接口比较统一. PHP对于不同的数据库采用不同的数据库访问接口,所以数据库访问代码的通用性不强.例如 ...
- web服务器的卸载
在卸载这三个应用之前,咱们可以在终端通过运行“dkpg -l”来查看软件状态. 方法一:选择dpkg -P来卸载软件. 因为dpkg --remove只是删除安装的文件,但不删除配置文件.而dpkg ...
- php 扩展编译linux
进入扩展库目录:$cd phpredis-master 需要root权限执行 执行:$ phpize 执行:$ ./configure 执行:$ make 执行:$ make install 编译 ...
- MongoDB 模糊查询,及性能测试
var mongodb = new MongoClient("mongodb://127.0.0.1:27017");//MongoServer.Create();//创建链接 v ...
- PC和单片机通过MODBUS RTU通信
最近研究了一下MODBUS通信,在STC12C5A60S2单片机上实现了MODBUS协议的部分功能,方便上位机从单片机系统上获取数据,比如由单片机获取的温度.湿度.或者控制信号的状态等.有了MODBU ...
- 【关于JavaScript】常见表单用户名、密码不能为空
在论坛等系统的用户注册功能中,如果用户忘记填写必填信息,如用户名.密码等,浏览器会弹出警告框,提示用户当前有未填信息. 这个典型的应用就是通过JavaScript实现的.如图所示是一个简单的用户注册页 ...
- Hbase对hive的支持没有hdfs的好的原因 及hbase什么时候使用 及rowkey设计技巧
hive-=mareduce 的 split 在 hbase就是 region了,,,,,,,访问region必须通过hregionserver 会造成regionser负担过大, 另外 reg ...
- android ADT Bundle for Mac下载地址
直接下载解压就能用 http://developer.android.com/sdk/index.html
- 安卓天天练练(十五)改造BasicSyncAdapter
谷歌的官方示例BasicSyncAdapter是Android Studio工程, 把它依样画葫芦到Eclipse上,然后改造成我需要的样式. 看官方示例源码的时候,看到EntryListActivi ...