[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 ...
随机推荐
- 精通 Oracle+Python,第 2 部分:处理时间和日期
从 Python 2.4 版开始,cx_Oracle 自身可以处理 DATE 和 TIMESTAMP 数据类型,将这些列的值映射到 Python 的 datetime 模块的 datetime 对象中 ...
- python基础之列表常用操作及知识点小结
列表(list) List(列表) 是 Python 中使用最频繁的数据类型.列表可以完成大多数集合类的数据结构实现.它支持字符,数字,字符串甚至可以包含列表(所谓嵌套).列表用[ ]标识,是pyth ...
- shell 常用
/etc/password 用户的 home路径设置 chwon groupname:username path_or_file -R # 修改文件左右者 chomd
- 关于 Log4Net
Log4Net是用来记录日志的,可以将程序运行过程中的信息输出到一些地方(文件.数据库.EventLog等),日志就是程序的黑匣子,可以通过日志查看系统的运行过程,从而发现系统的问题.日志的作用:将运 ...
- PHP之路——Redis安装
windows: redis下载链接:https://github.com/ServiceStack/redis-windows 然后编辑redis.windows.conf文件,我看网上有的教程说编 ...
- Entity Framework 实践系列 —— 搞好关系 - 单相思(单向一对一,one-to-one)【转】
原以为躲入代码世界,就可以不用搞关系,哪知“关系无处不在”.写代码多年之后,终于明白“面向对象的关键是搞好对象之间的关系”.而Entity Framework作为ORM中的明日之星,首当其冲的使命就是 ...
- OGNL学习-静态方法调用
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/> 1.小写 & ...
- 【Database】MySQL各版本的区别
MySQL 的官网下载地址:http://www.mysql.com/downloads/ 在这个下载界面会有几个版本的选择. 1. MySQL Community Server 社区版本,开源免费, ...
- PHP 之 Laravel 框架安装及相关开源软件
Laravel 被称为简洁.优雅的PHP开发框架,但第一次接触此框架的人有不少都卡在了安装上,其实在 Linux 下只需要很简单的几步就可以搞定,这里我们以 CentOS 下 PHP + Nginx ...
- 【转】不同VLAN之间相互通信及VTP、STP、EtherChannel概念
厘清最后一个概念. 转了网上两个相关帖子: http://www.net130.com/CMS/Pub/Tech/tech_zh/2009_03_12_97386_3.htm http://blog. ...