Freigeben über


New Reactive Extension Support for JavaScript Developers – Compatibility Builds, a lite version, and other improvements in RxJS 2.2

From the Rx team,

Claudio Caldato, Principal Program Manager Lead, MS Open Tech
Snesha Foss, Senior Program Manager, MS Open Tech
Kirk Shoop, Senior Software Development Engineer, MS Open Tech
Matthew Podwysocki, Software Engineer, Microsoft

Today Microsoft Open Technologies, Inc. (MS Open Tech), is happy to share the news of recent improvements we have made to Reactive Extensions.

We recently highlighted a release of Reactive Extensions Core as well as Rx.cpp. Today we want to let you know that RxJS 2.2 is now available via the Rx.js CodePlex project and includes various bug fixes and contributions from the community.

Reactive Extensions (Rx) is a programming model that allows developers to use a common interface for writing applications that interact with diverse data sources, like stock quotes, Tweets, UI events, and Web service requests. Since Rx was open-sourced by MS Open Tech in November, 2012, Rx has become an important under-the-hood component of several high-availability multi-platform applications, including NetFlix and GitHub. For a more detailed overview, have a look at the Beginner’s Guide to Reactive Extensions.

Updates:
Compatibility Builds

The core Rx.js now supports browsers that support ES5 only. We have moved all of our previously shipped ES5 polyfills to rx.compat.js. This saves a number of bytes, and allows developers to use any polyfill library of your choosing in order to support older browsers. We also have Compatibility builds for other key libraries, a few of which h are mentioned below.

Introducing Rx-Lite

One common question from our customers is, "Could we get a core of RxJS with a set of operators we use most often in a single, smaller library?" We hear you and have now provided rx.lite.js. This library consists of the most commonly used features, including factory methods for creating observable sequences, standard operators such as where, select, and zip, relative-time based operators and the most commonly used features from rs.async.js, including events, callbacks and promises bindings. The file size has is drastically reduced – currently just 7k when zipped. We also provide a compatibility build, rx.lite.compat.js to support older browsers.

Events, callbacks and promises with rx.async.js updates

Traditionally RxJS has not included many bridges to such things as events, promises or even callbacks. In version 2.2, we’re introducing the fromEvent to bind to events, fromCallback to support bridging to callbacks, fromNodeCallback to support Node.js style callbacks in which the error is always the first parameter, and Promises library binding in rx.async.js. With this library, you can easily compose events, promises and callbacks within a single library without having to bring in any other bridge library such as jQuery or HTML DOM. For older browsers, the compatibility build is rx.async.compat.js.

Control Virtual Time with rx.virtualtime.js

To decrease the size and scope of rx.js, all virtual time mechanisms were moved from the core library and into their own library, rx.virtualtime.js. This includes the VirtualTimeScheduler and the HistoricalScheduler.

Operator Changes and Additions:
  • The create factory function now takes as its return value a function which encapsulates disposal logic, or nothing if no cleanup is required. This deprecates the need for Observable.createWithDisposable.

  • Fixed the behavior of scan, to produce a sequence with only the seed if a sequence is empty but a seed was provided. If the sequence is empty and without a seed, an empty collection is created.

  • The share method was added to create a shortcut for publish().refCount(), a common function for sharing a single observable sequence.

  • A new shareLast method has been added to create a shortcut for the often used publishLast().refCount() to turn cold observables into hot observables and add reference counting.

  • The shareReplay method was added to create a shortcut for replay().refCount() to turn a hot observable into a cold observable and add reference counting.

  • The shareValue method was added to support a shortcut for publishValue().refCount() to publish a shared single value with reference counting added.

Other Recent Changes
  • rx.modern.js renamed to rx.js and old rx.js renamed to rx.compat.js for older browser support

  • VirtualTimeScheduler and HistoricalScheduler classes moved to rx.virtualtime.js

  • Rx.Observable.start and Rx.Observable.prototype.toAsync methods moved to rx.async.js

Deprecation Warnings:

The following Node,js specific methods in rx.node.js are being removed in favor of those in rx.async.js

  • Rx.Node.fromEvent - Now use Rx.Observable.fromEvent

  • Rx.Node.fromCallback – Now use Rx.Observable.fromCallback

The Hub engineering program has been a great place to collaborate on these projects, as these assignments give us the agility and resources to work with the community. Stay tuned for more updates soon, and please try out our work and pitch in!