bufferToggle(open: Observable, () => close: Observalbe : Observalbe<T[]>)

bufferToggle take two args, first is opening observable, seconde is a function which return an observable for closing.

The closeing observalbe only execute after opening emit value.

const source$ = Rx.Observable.interval(500);
const open$ = Rx.Observable.interval(1500);
const close$ = Rx.Observable.interval(1000); /** ---0---1---2---3---4---5---6---7---8---9----.... (source) -----------1-----------2-----------3--------... (open) --- ---x --- ---x --- ---x... (close)
bufferToggle(open$, () => close$) ------------------([2,3])-----([5.6])-----([8,9])--...
*/ const foo$ = source$.bufferToggle(open$, () => {
return close$;
}); foo$.subscribe(
(x) => console.debug("Next: " + x),
(err) => console.error(err),
() => console.info("DONE")
) /* "Next: 2,3"
"Next: 5,6"
"Next: 8,9"
"Next: 11,12"
...
*/

bufferWhen( () => Observable):

bufferWhen takes a function which return observable.

const source$ = Rx.Observable.interval(500);
const close$ = Rx.Observable.interval(1000); /** ---0---1---2---3---4---5---6---7---8---9----.... (source) -------0-------1-------2-------3-------4---.... (close) bufferWhen(()=>close$) -------(0)-----([1,2])-([3,4])-([5,6])--......
*/ const foo$ = source$.bufferWhen(() => close$); foo$.subscribe(
(x) => console.debug("Next: " + x),
(err) => console.error(err),
() => console.info("DONE")
) /* "Next: 0"
"Next: 1,2"
"Next: 3,4"
"Next: 5,6"
"Next: 7,8"
...
*/

[RxJS] Transformation operator: bufferToggle, bufferWhen的更多相关文章

  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: buffer, bufferCount, bufferTime

    This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...

  3. [RxJS] Transformation operator: scan

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

  4. [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 ...

  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. jQuery的延迟对象

    之前看别人的demo,发现在延迟对象被resolve时要执行的代码,有时会写在deferred.then方法里执行,有时会写在deferred.done方法里执行. 这让对延迟对象一知半解的我非常困惑 ...

  2. js实现中文简繁切换效果

    html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  3. 通过Servlet的response绘制页面验证码

    java部分 package com.servlet; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; ...

  4. WKWebView-b

    上一篇文章我们使用了JavaScriptCore框架重写了之前的示例,iOS8苹果偏爱HTML5,重构了UIWebVIew,给我们带来了WKWebView,使其性能.稳定性.功能大幅度提升,也更好的支 ...

  5. js共享onload事件

    问题:通过js进行事件绑定,必须在HTML文档加载完成后再执行js脚本,否则可能因DOM不完整导致无法完成预计的效果,但对于不同的需求如何选用最佳的实现方式呢,这里做了整理,可以做参考. 一.对于小型 ...

  6. 第一个deeplearning4jproject跑起

    deeplearning4j是基于java的深度学习库,当然,它有许多特点,但暂时还没学那么深入,所以就不做介绍了 需要学习dl4j,无从下手,就想着先看看官网的examples,于是,下载了exam ...

  7. 最常用的动态sql语句梳理——分享给使用Mybatis的小伙伴们!

    公司项目中一直使用Mybatis作为持久层框架,自然,动态sql写得也比较多了,最常见的莫过于在查询语句中使用if标签来动态地改变过滤条件了.Mybatis的强大特性之一便是它的动态sql,免除了拼接 ...

  8. jquery中each遍历对象和数组示例

    通用遍历方法,可用于遍历对象和数组.$().each(),回调函数拥有两个参数: 第一个为对象的成员或数组的索引,第二个为对应变量或内容.如需退出each循环可使回调函数返回false 现有如下两个s ...

  9. oc调用c++接口时 报错 Undefined symbols for architecture i386:

    当在oc中调用c++中的方法时,发现说c++中的方法没定义或是找不到 Undefined symbols for architecture i386: "_desTYData", ...

  10. Asterix and Obelix

    uva10246:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...