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.

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.

[RxJS] Combination operator: withLatestFrom的更多相关文章

  1. [RxJS] Combination operator: combineLatest

    While merge is an OR-style combination operator, combineLatest is an AND-style combination operator. ...

  2. [RxJS] Combination operator: zip

    CombineLatest and withLatestFrom are both AND-style combination operators. In this lesson, we will l ...

  3. [RxJS] Transformation operator: buffer, bufferCount, bufferTime

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

  4. [RxJS] Transformation operator: scan

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

  5. rxjs自定义operator

    rxjs自定义operator

  6. [RxJS] Utility operator: do

    We just saw map which is a transformation operator. There are a couple of categories of operators, s ...

  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] Transformation operator: repeat

    Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...

随机推荐

  1. mysql备份sql,脚本

    MySQL 安装位置:/usr/local/mysq 论坛数据库名称为:bbs MySQL root 密码:123456 数据库备份目的地:/var/db_backup/ #! /bin/bash / ...

  2. iscroll横向滑动(当前页状态标记自动变化)

    var myScroll; function loaded(){ myScroll = new iScroll('wrapper',{ snap:true, checkDOMChanges:true, ...

  3. PHPCMS实现文章置顶功能的方法

    我个人喜欢把PHPCMS当作博客来用,而作为一个博客,怎能少了文章置顶功能呢?其中用PHPCMS实现置顶功能非常简单,无非是修改下推荐位的名称为置顶,然后在文章列表中推送需要置顶的文章罢了. 不过博客 ...

  4. 批处理协同blat自动发邮件

    Blat - A Windows (32 & 64 bit) command line SMTP mailer. Use it to automatically eMail logs, the ...

  5. 练习2 H题 - 求数列的和

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 数列的 ...

  6. linux下配置NFS服务器

    (声明:本文大部分文字摘自Linux NFS服务器的安装与配置) 一.NFS简介     NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Su ...

  7. HTML5之一HTML5简介

    1.什么是HTML5? HTML5是HTML的新一代标准.以前版本的HTML标准4.01发布于1999. 自1999年以后,web已经有了翻天覆地的变化. 实际上HTML5仍旧是开发中的一个标准.但是 ...

  8. bzoj 2734: [HNOI2012]集合选数 状压DP

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 560  Solved: 321[Submit][Status ...

  9. PHP日常杂记

    1.php点击按钮跳转页面 <input type="button" onclick="window.location.href='login.php'" ...

  10. Linux Shell编程(15)——操作字符串

    Bash已经支持了令人惊讶的字符串操作的数量.不幸地,这些工具缺乏统一的标准.一些是参数替换的子集,其它受到UNIX的expr命令的功能的影响.这导致不一致的命令语法和冗余的功能,但这些并没有引起混乱 ...