JavaScript 的 Reactive 扩展:RxJS
静态网页已经成为历史,如今的web设计趋势是预测客户想法并提供更好的互动功能,例如自动填写表单、搜索Wikipedia等。RxJS框架可以很方便地为鼠标和键盘事件提供响应。
- rx.js - core library for ES5 compliant browsers and runtimes
- rx.compat.js - core library for older non-ES5 compliant browsers.
- rx.aggregates.js - aggregation event processing query operations
- rx.async.js - async operationrs such as events, callbacks and promises
- rx.async.compat.js - async operationrs such as events, callbacks and promises with support back to IE6
- rx.binding.js - binding operators including multicast, publish, publishLast, publishValue, and replay
- rx.coincidence.js - reactive coincidence join event processing query operations
- rx.experimental.js - experimental operators including imperative operators and forkJoin
- rx.joinpatterns.js - join patterns event processing query operations
- rx.testing.js - used to write unit tests for complex event processing queries.
- rx.time.js - time-based event processing query operations.
- rx.virtualtime.js - virtual-time-based schedulers.
示例代码:
var $input = $('#input'), $results = $('#results'); /* Only get the value from each key up */ var keyups = Rx.Observable.fromEvent(input, 'keyup') .map(function (e) { return e.target.value; }) .filter(function (text) { return text.length > 2; }); /* Now throttle/debounce the input for 500ms */ var throttled = keyups .throttle(500 /* ms */); /* Now get only distinct values, so we eliminate the arrows and other control characters */ var distinct = keyups .distinctUntilChanged();
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!