JavaScript 的 Reactive 扩展:RxJS

jopen 10年前

静态网页已经成为历史,如今的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();

项目主页:http://www.open-open.com/lib/view/home/1410671373226