zoukankan      html  css  js  c++  java
  • [RxJS] Combination operator: combineLatest

    While merge is an OR-style combination operator, combineLatest is an AND-style combination operator. This lesson explains what AND-style combination means, and how you can join values from two or more Observables in a formula.

    At the begin, there is no value emit, then bar has value 0, but foo has no value still. Therefore also no value emit, until foo has the first value 0, then output the final value as 0.

    var foo = Rx.Observable.interval(500).take(4);
    var bar = Rx.Observable.interval(300).take(5);
    
    /*
    ----0----1----2----(3|)     (foo)
    --0--1--2--3--(4|)          (bar)
       combineLatest((x, y) => x+y)
    ----01--23-4--(56)-(7|)
    */
    
    var bmi = foo.combineLatest(bar,(x,y) => x+y);
    
    // merge: OR
    // combineLatest: AND
                                   
    bmi.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"
    "next 5"
    "next 6"
    "next 7"
    "done"*/
  • 相关阅读:
    装饰器
    函数的初识
    python的文件操作
    深浅copy
    set集合,是一个无序且不重复的元素集合
    基础数据类型 :字典
    列表的增删改查
    易错点 默认参数陷阱
    js中Array对象常用方法
    printf用法demo
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5531702.html
Copyright © 2011-2022 走看看