take(), takeLast(), first(), last(), those opreators all take number or no param. takeUtil and takeWhile will take Observalbe and function.

takeUntil(notifier: Observable): Stop when another observalbe happens

var foo = Rx.Observable.interval(1000);
var btn = document.querySelector('#stop');
var stop$ = Rx.Observable.fromEvent(btn, 'click');
/*
--0--1--2--3--4--5--6--7--...
takeUntil()
--0--1--2--3--4|
*/ var bar = foo.takeUntil(stop$); bar.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next 0"
"next 1"
"next 2"
"next 3"
"next 4"
"done"
*/

takeWhile(predicate: function): Abort when it meets the predicate function.

var foo = Rx.Observable.interval(1000);
/*
--0--1--2--3--4--5--6--7--...
takeWhile(x => x < 3)
--0--1--2--|
*/ var bar = foo.takeWhile((x)=>{
return x<3;
}); bar.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next 0"
"next 1"
"next 2"
"done"
*/

[RxJS] Filtering operators: takeUntil, takeWhile的更多相关文章

  1. [RxJS] Filtering operators: skipWhile and skipUntil

    After takeUntil() and takeWhile() function, let's have a look on skipWhile() and skilUntil() functio ...

  2. [RxJS] Filtering operators: take, first, skip

    There are more operators in the filtering category besides filter(). This lesson will teach how take ...

  3. [RxJS] Filtering operators: distinct and distinctUntilChanged

    Operator distinct() and its variants are an important type of Filtering operator. This lessons shows ...

  4. [RxJS] Filtering operators: takeLast, last

    Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...

  5. [RxJS] Filtering operators: throttle and throttleTime

    Debounce is known to be a rate-limiting operator, but it's not the only one. This lessons introduces ...

  6. [RxJS] Transformation operators: debounce and debounceTime

    Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...

  7. [RxJS] Transformation operators: delay and delayWhen

    This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...

  8. [RxJS] Creation operators: interval and timer

    It is quite common to need an Observable that ticks periodically, for instance every second or every ...

  9. [RxJS] Creation operators: empty, never, throw

    This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...

随机推荐

  1. tornado学习精要

    最简单的应用在程序的最顶部,我们导入了一些Tornado模块.虽然Tornado还有另外一些有用的模块,但在这个例子中我们必须至少包含这四个模块. 12341234包括了一个有用的模块(tornado ...

  2. webapp框架—学习AngularUI1(demo折腾)

    angularUI下载地址:https://github.com/Clouda-team/BlendUI 下载解压后,demo在根目录 现在测试官网demo的使用 用浏览器打开mobile-angul ...

  3. mysql进阶1

    在我们用php处理数据的时候总会遇到些比较麻烦的事情,比如:两个二维数组,一个装的是文章分类表内容,一个装的是文章列表,有关联字段,完全等值,要求在列表文章的时候同时能在标题的前面显示栏目名称,此时循 ...

  4. 帝国cms 灵动标签调用顶级栏目导航

    [e:loop={"select classname,classpath from [!db.pre!]enewsclass where bclassid=0 order by classi ...

  5. C# 启动和结束一个线程

    在程序执行中会遇到启动本软件的exe问,或者启用其它的exe文件,已达到执行某些操作的作用.下面是两种最常见的启动exe文件. 1.调用系统dll使用其提供的方法. 引用的dll, [DllImpor ...

  6. MATLAB灰度图、中值滤波图

    x=imread(‘x.jpg’); x=rbg2gray(x);  %转成灰度图像 k=medfilt2(x);   %中值滤波,默认为3X3矩阵 figure, imshow(k); medfil ...

  7. id类型

    id类型 在Objective-C 中,id 类型是一个独特的数据类型.在概念上,类似Java 的Object 类,可以转换为任何数据类型.换句话说,id 类型的变量可以存放任何数据类型的对象.在内部 ...

  8. BZOJ 1001 狼捉兔子

    Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个 ...

  9. iOS-NSTimer-pause-暂停-引用循环

    7月26日更新: 今天更新的主要目的是因为暂停!!!! 注:不推荐使用,并不是这样有错,而是因为这样写代码的规范问题,代码要有可读性,遵循代码即文档,使用暂停在团队合作中可能会带来误会,非必要不建议使 ...

  10. asp.net 类库中获取session c#类中获取session

    asp.net  类库中获取session c#类中获取session 1. 先引入命名空间 using System.Web; using System.Web.SessionState; 在使用H ...