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 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!