首页 > Web开发 > 详细

[RxJS] Filtering operators: skipWhile and skipUntil

时间:2016-05-25 20:17:32      阅读:262      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/Answer1215/p/5528061.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!