[RxJS] Filtering operators: takeUntil, takeWhile
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的更多相关文章
- [RxJS] Filtering operators: skipWhile and skipUntil
After takeUntil() and takeWhile() function, let's have a look on skipWhile() and skilUntil() functio ...
- [RxJS] Filtering operators: take, first, skip
There are more operators in the filtering category besides filter(). This lesson will teach how take ...
- [RxJS] Filtering operators: distinct and distinctUntilChanged
Operator distinct() and its variants are an important type of Filtering operator. This lessons shows ...
- [RxJS] Filtering operators: takeLast, last
Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...
- [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 ...
- [RxJS] Transformation operators: debounce and debounceTime
Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...
- [RxJS] Transformation operators: delay and delayWhen
This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...
- [RxJS] Creation operators: interval and timer
It is quite common to need an Observable that ticks periodically, for instance every second or every ...
- [RxJS] Creation operators: empty, never, throw
This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...
随机推荐
- Sublime Text 2中前端必备的常用插件
Sublime Text 2安装的插件和所有预置的插件全部在Packages文件下,可以直接通过”preferences“—>”Browse Pakcages“来访问. Sublime Text ...
- Laravel之路——file缓存修改为redis缓存
1.Session: 修改.evn文件: SESSION_DRIVER:redis (如果还不行的话,修改config/session.php的driver) 2.缓存修改为redis 注意:使用 L ...
- android学习(2) 多线程的理解
多线程操作UI的运行原理: UI线程:首先启动app时,系统会自动启动一个UI线程,然后此线程会创建一个Looper(注:Looper构造函数会实例化一个MessageQueue的消息队列存在变量mQ ...
- Hdu5510 Bazinga
Description Ladies and gentlemen, please sit up straight. Don't tilt your head. I'm serious. For \(n ...
- 5种php加密工具zendGuard、ionCube、SourceCop、SourceGuardian、phpShield
PHP做桌面应用的想法: 除去icudt55.dll,PHP7用7ZIP压缩后不足7MB,而PHP自带了SQLite和CLI HTTP Server,用户打开浏览器就能访问PHP开发的桌面应用.如果源 ...
- android和struts2实现android文件上传
1.开发准备如下2个工具类 package org.lxh.util; import java.io.BufferedReader; import java.io.InputStreamReader; ...
- log4j_slf4j log4j.properties
hibernate 使用的日志是slf4j,而 slf4j又有各种实现策略. 使用log4j 就是其中一种方式. 需要的jar 包: log4j-1.2.16.jar slf4j-api-1.6.1. ...
- u-boot中分区和内核MTD分区关系
一.u-boot中环境变量与uImage中MTD的分区关系 分区只是内核的概念,就是说A-B地址放内核,C-D地址放文件系统,(也就是规定哪个地址区间放内核或者文件系统)等等. 一般我们只需要分3-4 ...
- SQL Server 2005/2008 触发器的管理和查看
1.通过可视化操作来管理和查看触发器 在Microsoft SQL Server Management Studio中,选中某一数据库的某一张表时,在“对象资源管理器详细”窗口中有“触发器”项.通过“ ...
- 【狼】unity3d collision获取碰撞的点的位置
void OnCollisionEnter(Collision ctl) { ContactPoint contact = ctl.contacts[]; Quaternion rot = Quate ...