[RxJS] Combination operator: withLatestFrom
2016-05-26 19:39
387 查看
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLatestFrom, another AND-style combination operator, and how it works essentially as map() operator, with some combination properties.
The foo is the main stream, when foo emit each time, it will take the latest value from bar, if the value from bar is 1, then convert foo to upcase string, otherwise lower case string.
var foo = Rx.Observable.interval(400) .zip(Rx.Observable.of('h', 'e', 'l', 'l', 'o'), (__, x) => x); var bar = Rx.Observable.interval(300) .zip(Rx.Observable.of(0,1,1,0,0,1,0,0,1), (__ ,x) => x); /* ----h----e----l----l----o| (foo) --0--1--1--0--0--1--0--0--1| (bar) withLatestFrom((c,n) => n === 1 ? c.toUpperCase() : c.toLowerCase()) ----h----E----l----L----o| */ var combined = foo.withLatestFrom(bar, (c,n) => n === 1 ? c.toUpperCase() : c.toLowerCase()); combined.subscribe( function (x) { console.log('next ' + x); }, function (err) { console.log('error ' + err); }, function () { console.log('done'); }, ); /* "next h" "next E" "next l" "next l" "next O" "done" */
The foo is the main stream, when foo emit each time, it will take the latest value from bar, if the value from bar is 1, then convert foo to upcase string, otherwise lower case string.
相关文章推荐
- JSP和Servlet之间跳转总结
- js模版引擎介绍
- 网页进度条实现
- [RxJS] Combination operator: zip
- Javascript 读取浏览器名及版本号
- 主流web界面播放器的页面引用以及浏览器的支持情况分析(VLC)
- 每日构建中增加js的压缩混淆
- 2016年5月26日晚上(妙味课堂js基础-2笔记二(DOM))
- js之工具函数
- JavaScript中的各种操作符使用总结
- 2016年5月26日下午(妙味课堂js基础-2笔记一(DOM))
- 实现表单checkbox获取已选择的值js代码
- 浅析JavaScript中的对象类型Object
- 显示缩略列表 JS DOM
- bzoj 4460 : [Jsoi2013]广告计划
- 如何在文章/随笔中添加可运行的js代码
- 纯js提交get和post请求
- JSON的解析与序列化
- C#中对于json格式数据的处理
- jsp 页面上根据id显示名字的方法