zoukankan      html  css  js  c++  java
  • [RxJS] Filtering operators: takeUntil, takeWhile

    take(), takeLast(), first(), last(), those opreators all take number or no param. takeUtil and takeWhile will take Observalbe and function.

    takeUntil(notifier: Observable): Stop when another observalbe happens

    var foo = Rx.Observable.interval(1000);
    var btn = document.querySelector('#stop');
    var stop$ = Rx.Observable.fromEvent(btn, 'click');
    /*
    --0--1--2--3--4--5--6--7--...
           takeUntil()
    --0--1--2--3--4|
    */
    
    var bar = foo.takeUntil(stop$);
    
    bar.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"
    "done"
      */

    takeWhile(predicate: function): Abort when it meets the predicate function.

    var foo = Rx.Observable.interval(1000);
    /*
    --0--1--2--3--4--5--6--7--...
           takeWhile(x => x < 3)
    --0--1--2--|
    */
    
    var bar = foo.takeWhile((x)=>{
                 return x<3;             
             });
    
    bar.subscribe(
      function (x) { console.log('next ' + x); },
      function (err) { console.log('error ' + err); },
      function () { console.log('done'); },
    );
    
      /*
    "next 0"
    "next 1"
    "next 2"
    "done"
      */
  • 相关阅读:
    iOS:hidesBottomBarWhenPushed的正确用法
    清理缓存
    iOS常见问题(2)
    iOS常见问题(1)
    Xcode文档下载与安装路径
    文本属性Attributes
    NSAttributedString
    protocol
    类的本质、description方法、SEL、NSLog输出增强
    分类-Category
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5528027.html
Copyright © 2011-2022 走看看