[RxJS] Filtering operators: skipWhile and skipUntil

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[RxJS] Filtering operators: skipWhile and skipUntil相关的知识,希望对你有一定的参考价值。

After takeUntil() and takeWhile() function, let‘s have a look on skipWhile() and skilUntil() functions.

 

SkipWhile(predicate: function): Skip the value if meet the predicate function.

var foo = Rx.Observable.interval(1000);
/*
--0--1--2--3--4--5--6--7--...
  skipWhile(x => x < 3).take(3)
-----------3--4--5|
*/

var bar = foo.skipWhile((x)=>{
             return x<3;             
         }).take(3);

bar.subscribe(
  function (x) { console.log(‘next ‘ + x); },
  function (err) { console.log(‘error ‘ + err); },
  function () { console.log(‘done‘); },
);

  /*
"next 3"
"next 4"
"next 5"
"done"
  */

 

skipUntil(Observable): after 3 seconds, click the start button, to start the foo observalbe.

var foo = Rx.Observable.interval(1000);
var start$ = Rx.Observable.fromEvent(document.querySelector(‘#start‘), ‘click‘);
/*
--0--1--2--3--4--5--6--7--...
  skipUntil(start$)
-----------3--4--5|
*/

var bar = foo.skipUntil(start$);

bar.subscribe(
  function (x) { console.log(‘next ‘ + x); },
  function (err) { console.log(‘error ‘ + err); },
  function () { console.log(‘done‘); },
);

  /*
"next 3"
"next 4"
"next 5"
"done"
  */

 

以上是关于[RxJS] Filtering operators: skipWhile and skipUntil的主要内容,如果未能解决你的问题,请参考以下文章

[RxJS] Filtering operators: throttle and throttleTime

[RxJS] Filtering operators: distinct and distinctUntilChanged

[RxJS] Filtering operator: single, race

RxJS过滤数据流操作符学习 (Filtering Operators)

rxjs/operators:找不到模块

[RxJS] What RxJS operators are