[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 ...
随机推荐
- InstallShield:自己备份
LIST listData;//声明listData listData = ListCreate(STRINGLIST);//创建一个空的实际字符串或数字列表. //参数都是在上个界面中赋值,然后在下 ...
- base 使网页所有超链接都以新超链接的方式打开
需求,网页有许多超链接,但是没有加 target="_blank",现在需要所有超链接都已新页面的方式打开 在head头添加 <base target="_blan ...
- 工程经济学economics of project summarize
什么是财务杠杆效应 财务杠杆效应是指由于固定费用的存在而导致的,当某一财务变量以较小幅度变动时.另一相关变量会以较大幅度变动的现象.也就是指在企业运用负债筹资方式(如银行借款.发行债券)时所产生的普通 ...
- python消息队列snakemq使用总结
Python 消息队列snakemq总结 最近学习消息总线zeromq,在网上搜了python实现的消息总线模块,意外发现有个消息队列snakemq,于是拿来研究一下,感觉还是很不错的,入手简单使用也 ...
- 一个简单的webservice调用
我们先创建一个简单空web应用程序 然后添加新建项目 //我们创建一个peson对象,产生数据标识返回 using System; using System.Collections.Generic; ...
- 1、C# MVC学习之NVelocity基本使用
小白一个,刚刚开始学,大神不要笑话...... NVelocity是一个很容易上手的框架,从它开始学习,可以循序渐进 首先,创建空web应用程序,新建一般处理程序 Login2.ashx 然后,引入N ...
- 小A老空调需求管理小记
1. 关注一个动作的流程和内容 比如登录,我需要提供的是登录接口,但是登录是否只是一个动作?一个动作一定不完整,还应该包括动作的内容和步骤(流程),这里有两个问题:就是落地和把问题想复杂了:其实登录还 ...
- ios8新特性widget开发-b
os8发布已经有一段时间了,伴随着ios8同时也出现了许多新的特性,ios系统将会越来越开放,这是好事.其中一个新特性就是在下拉通知栏里加入了个性的widget,开发者可以自己定义widget的样式内 ...
- iOS:使用导航栏
要求使用ARC // // main.m // Hello // // Created by lishujun on 14-8-28. // Copyright (c) 2014年 lishujun. ...
- Data Guard配置后续检查
Data Guard配置后续检查 1.打开生产端节点192.166.1.190上的数据库实例: SQL>startup; 2.打开容灾端节点192.166.1.60上的数据库实例: SQL> ...