ReactiveX是一个通过使用可观察序列来合成异步和基于事件的程序的库。
它扩展了observer模式,以支持数据和/或事件序列,并增加了操作符,允许你声明式地将序列组合在一起,同时抽象出低级线程、同步、线程安全、并发数据结构和非阻塞I/O等问题。
示例代码:
var $iput = $('#iput'), $results = $('#results');/* Oly get the value from each key up */var keyups = Rx.Observable.fromEvet(iput, 'keyup') .map(fuctio (e) { retur e.target.value; }) .filter(fuctio (text) { retur text.legth > 2; });/* Now throttle/debouce the iput for 500ms */var throttled = keyups .throttle(500 /* ms */);/* Now get oly distict values, so we elimiate the arrows ad other cotrol characters */var distict = keyups .distictUtilChaged();









评论