[rxjs] Async, handle data over time

If I have an array, and I want to apply filter, map, forEach to it.

let Observable = Rx.Observable;

let ary = Observable.fromArray([1,2,5,4,6]);

ary
  .filter((item) => item % 2===1)
   .map((item)=> item + "!")
   .forEach((item) => console.log(item));
 /*
"1!"
"5!"
*/

 

The same opreations filter, map, foreach can also handler async data which arrive over time:

let Observable = Rx.Observable;

let ary = Observable.interval(500).take(8);

ary
  .filter((item) => item % 2===1)
   .map((item)=> item + "!")
   .forEach((item) => console.log(item));

/**
"1!"
"3!"
"5!"
"7!"
*/

 

posted @ 2015-08-19 21:33  Zhentiw  阅读(196)  评论(0编辑  收藏  举报