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"*/
  • 相关阅读:
    indexOf & lastIndexOf
    document.referrer
    函数组合
    v-model绑定vuex中的数据
    图片懒加载
    flex布局问题
    js常见错误类型
    es5/es6继承的区别
    合并两个有序数组
    lettcode 90 子集II
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5531702.html
Copyright © 2011-2022 走看看