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. js获取时间加多山天和时间戳转换成日期

    function huoqu(){    var data = $("#data").val();//获取的时间    var day = $('#day').val();//往后 ...

  2. base 使网页所有超链接都以新超链接的方式打开

    需求,网页有许多超链接,但是没有加 target="_blank",现在需要所有超链接都已新页面的方式打开 在head头添加 <base target="_blan ...

  3. Hierarchy Viewr 配合 adb 命令 查看窗口属性

    Hierarchy Viewr 可以看到当前 的 窗口层次如下

  4. [python]文本处理1.2

    1.0初步完成了文本截取需要信息的处理 1.1 修复了格式所造成的遗漏字符 1.2 去除了遗漏字符中的多余字符 bug-文本test14 有遗漏字符 bug-修复的遗漏字符中含有\n 未被识别为换行符

  5. 浙工大C语言入门指南 (仅供参考)

    C语言书籍推荐 浙工大图书馆中,计算机的书都集中在三楼TP区.我个人推荐下面这么几本书. <Head First C>.Head First系列的书质量基本都很高.该书有很多插图,总体上就 ...

  6. ASP.NET MVC轻教程 Step By Step 5——初识表单

    上一节我们将留言列表显示在Index视图里了,现在该添加一个留言的表单,好让用户自己添加留言. 首先在HomeController中添加一个名为“Write”的动作方法. public ActionR ...

  7. Codeforces Round #315 (Div. 2)

    这次可以说是最糟糕的一次比赛了吧, 心没有静下来好好的去思考, 导致没有做好能做的题. Problem_A: 题意: 你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的 ...

  8. CSS3随笔系列之transform(一)—— transform-origin

    transform-origin属性平时似乎用得很少,它决定了变换时依赖的原点.基本的属性特性可以参考CSS手册. 如果在H5动画项目中,用到旋转的话,它还是不能小觑的. 假如我们做一个秋千效果 其实 ...

  9. 高性能页面加载技术(流水线加载)BigPipe的C#简单实现(附源码)

    一,BigPipe简介 BigPipe是一个重新设计的基础动态网页服务体系.大体思路是,分解网页成叫做Pagelets的小块,然后通过Web服务器和浏览器建立管道并管理他们在不同阶段的运行.这是类似于 ...

  10. DIV焦点事件

    div本来是没有focus和blur事件的. 如果用div来模拟一个input标签,同时需要它和input一样响应focus和blur事件, 就需要给他加上attribute:tabindex An ...