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的更多相关文章

  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: scan

    All of the combination operators take two or more observables as input. These operators may also be ...

  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. JavaScript学习心得(八)

    Cookie是Netscape发明的技术,是动态网站必不可少的部分,用于浏览器请求Web页面的超文本传输协议是一种无状态的协议. 两种方法维护状态:使用会话(session)(使用服务器技术实现,数据 ...

  2. Activity singleInstance启动模式

    全局单例模式 如果 是新建Activity, 则新建一个Task, 然后将ActivityRecord单独放在其中 如果已经存在这个Activity, 则直接将这个Activity转到前台

  3. iOS: XCode6 beta 6 错误

    在使用XCode6 Beta6时, 遇到"__TFSs15_arrayForceCastU___FGSaQ__GSaQ0__"错误: 在http://stackoverflow.c ...

  4. 从文章"避免复制与粘贴"到文章"Extract Method"的反思(3)

    在牛人的博客中提到了..如果你的代码可以copy-past的时候,那么久证明你的代码出现了重复.而这种重复仅仅是虚假的代码行的增加而不是像其他的代码复用那样降级成本. copy-pase代码意味着你违 ...

  5. svn代码统计

    http://chenzhou123520.iteye.com/blog/1436653

  6. ORACLE数据缓冲区DB cache

    DB CACHE是以数据块为单位组织的缓冲区,数据库刚刚启动的时候,DB CACHE中几乎没有用户数据的缓冲,当会话访问数据库中的表或索引时,首先会检查DB CACHE中是否存在该数据,如果不存在,就 ...

  7. WPF Application 执行顺序

    public static void Main() { ApplicationClass.App app = new ApplicationClass.App();app.InitializeComp ...

  8. 哈希表(Hashtable)简述

    一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似keyvalue的键值对,其中 ...

  9. Selenium稳定性 Test

    [Test] public void DriverExtension_Wait() { var driver = new FirefoxDriver(); driver.Navigate().GoTo ...

  10. UVa 10294 Arif in Dhaka (First Love Part 2)(置换)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35397 [思路] Polya定理. 旋转:循环节为gcd(i,n) ...