[RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. Buffer groups consecutive values together, emitting the output as an array. The buffer variants and their arguments allow to specify when to close the buffers.
buffer(close observable): According to another observalbe to group items.
var foo = Rx.Observable.of('h', 'e', 'l', 'l', 'o')
.zip(Rx.Observable.interval(600).take(5), (x,y) => x);
var bar = Rx.Observable.interval(900).take(3);
/*
-----h-----e-----l-----l-----o| (foo)
--------0--------1--------2| (bar)
buffer(bar)
--------h--------e--------ll|
*/
var result = foo.buffer(bar);
result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
/*
"next h"
"next e"
"next l,l"
"done"
*/
bufferTime(number):
var foo = Rx.Observable.of('h', 'e', 'l', 'l', 'o')
.zip(Rx.Observable.interval(600).take(5), (x,y) => x);
/*
-----h-----e-----l-----l-----o| (foo)
--------x--------x--------x| (900ms)
bufferTime(900)
--------h--------e--------ll|
*/
var result = foo.bufferTime(900);
result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
/*
"next h"
"next e"
"next l,l"
"done"
*/
bufferCount(number):
var foo = Rx.Observable.of('h', 'e', 'l', 'l', 'o')
.zip(Rx.Observable.interval(600).take(5), (x,y) => x);
/*
-----h-----e-----l-----l-----o| (foo)
bufferCount(2)
----------([h,e])------([l,l])([o|])l
*/
var result = foo.bufferCount(2);
result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
/*
"next h,e"
"next l,l"
"next o"
"done"
*/
[RxJS] Transformation operator: buffer, bufferCount, bufferTime的更多相关文章
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
- [RxJS] Transformation operator: scan
All of the combination operators take two or more observables as input. These operators may also be ...
- [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 ...
随机推荐
- 使用css3画饼图
CSS3 Gradient介绍参考地址: http://www.cnblogs.com/lhb25/archive/2013/01/30/css3-linear-gradient.html http: ...
- 《JavaScript高级程序设计 第3版》-学习笔记-2
P31-P82页 1.相等不相等与全等不全等 相等不相等:先转换后比较.对于只有一个对象,调用valueOf方法得到基本类型值再按基本类型转换:如果两个都是对象,则比较他们是否是同一个对象(引用或指针 ...
- MongoDB在windows服务器安装部署及远程连接MongoDB
(.\是表示在服务器的windows powershell下需要 表示信任此命令才会执行不然会报错,自己电脑上使用时可去掉.\) 在本地使用都不需要开启权限而在服务器上需要开启安全模式所以需要在原本的 ...
- 一张图看懂DNS域名解析全过程
DNS域名解析是互联网上非常重要的一项服务,上网冲浪(还有人在用这个词吗?)伴随着大量DNS服务来支撑,而对于网站运营来说,DNS域名解析的稳定可靠,意味着更多用户的喜欢,更好的SEO效果和更大的访问 ...
- 学习Swift--属性
属性 属性将值跟特定的类.结构或枚举关联.存储属性存储常量或变量作为实例的一部分,而计算属性计算(不是存储)一个值.计算属性可以用于类.结构体和枚举,存储属性只能用于类和结构体. 存储属性和计算属性通 ...
- 转载:如何避免代码中的if嵌套
http://top.jobbole.com/4960/ http://stackoverflow.com/questions/24430504/how-to-avoid-if-chains 在Sta ...
- spoj gss2 : Can you answer these queries II 离线&&线段树
1557. Can you answer these queries II Problem code: GSS2 Being a completist and a simplist, kid Yang ...
- Reason: image not found 错误解决方法
dyld: Library not loaded: /System/Library/Frameworks/Social.framework/Social Referenced from: /var ...
- BlockingQueue队列学习
今天看了下BlockingQueue的几种实现,记录下以便以后复习. 首先来看一下BlockingQueue的家族成员: BlockingQueue除了先进先出外,还有两个操作:在队列为空时,获取元素 ...
- 添加Fragment注意事项
配置(Configuration )改变是Android应用生命周期的一部分,如果发生了该事件(屏幕从横屏换行为竖屏),就会导致Activity被销毁然后重新创建.就算您在配置文件中设定Activit ...