[rxjs] Async, handle data over time

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

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:async

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!"
*/
相關文章
相關標籤/搜索