[RxJS] Filtering operators: takeLast, last
2016-05-25 16:47
453 查看
Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable execution. In this lesson we will see similar operators which refer instead to the end of an Observable execution, such as takeLast().
takeLast(number): takeLast requires the source has completion.
If replace range() to interval(1000).take(7); then we will wait 7 seconds before the result comes out sync.
last():
takeLast(number): takeLast requires the source has completion.
var foo = Rx.Observable.range(1,7); /* --0--1--2--3--4--5--6--7-| takeLast(2) ---------------------------(67|) */ var bar = foo.takeLast(2); bar.subscribe( function (x) { console.log('next ' + x); }, function (err) { console.log('error ' + err); }, function () { console.log('done'); }, ); /* "next 6" "next 7" "done" */
If replace range() to interval(1000).take(7); then we will wait 7 seconds before the result comes out sync.
last():
var foo = Rx.Observable.range(1,7); /* --0--1--2--3--4--5--6--7-| last() ---------------------------(7|) */ var bar = foo.last(); bar.subscribe( function (x) { console.log('next ' + x); }, function (err) { console.log('error ' + err); }, function () { console.log('done'); }, ); /* "next 7" "done" */
相关文章推荐
- 欢迎使用CSDN-markdown编辑器
- Javascript判断页面刷新或关闭的方法
- js 正则 demo
- 解决DWZ框架文件上传没有关闭当前的dialog的问题
- javascript 笔记——setTimeout的参数问题
- [RxJS] Filtering operators: take, first, skip
- phaser.js入门篇
- js将本地时间与服务器时间同步
- js prototype介绍
- js every扩展
- [RxJS] Filtering operator: filter
- [JavaScript] 判断键盘同时按某些键时执行操作。
- 各个JSON技术的比较
- 在js里通过id控制表或div的隐藏和显示,以及把id前缀相同的div全部隐藏起来
- Retrofit + GSON处理JSON模板
- 读书笔记1---JavaScript词法结构
- js常见事件及案例-onFocus
- 将XML文件中的内容转换为Json对象
- javascript判断浏览器类型(咋个办呢 zgbn)
- js 将json字符串转换为json对象的方法解析