RxJS v4.1.0 Release Notes
Release Date: 2016-03-07 // about 7 years ago-
๐ We are happy to announce the release of RxJS version 4.1. With this release came a few new additions as well as a new system for pulling in what you want.
Some of the changes are the following:
- ๐ Build What You Want with
@rxjs/rx
- โ Adding
repeatWhen
- Parity with RxJS v5 names
- Other changes
๐ Build What You Want with
@rxjs/rx
๐ One of the biggest requests with RxJS was to build only what you wanted. In previous attempts, we looked at a CLI to build what you wanted, but that was suboptimal experience. Instead, we have ported the existing code base to CommonJS format so that it works right out of the box with Node.js, or with your favorite bundler whether it is Browserify, Webpack, Rollup, etc.
0๏ธโฃ By default, this brings in all of RxJS when you require the
@rxjs/rx
module:const Rx = require('@rxjs/rx');const subscription = Rx.Observable.from([1,2,3]) .filter(x =\> x % 2 === 0) .map(x =\> x + 2) .subscribe(x =\> console.log(`The answer is ${x}`));// =\> The answer is 4
Now it is possible to bring in as much or as little as you want by only including the operators you want:
const fromArray = require('@rxjs/rx/observable/fromArray');const filter = require('@rxjs/rx/observable/filter');const map = require('@rxjs/rx/observable/map');const source = fromArray([1,2,3]);const filtered = filter(source, x =\> x % 2 === 0);const mapped = map(filtered, x =\> x + 2);const subscription = mapped.subscribe( x =\> console.log(`The answer is ${x}`) );// =\> The answer is 4
Not only can you bring in certain operators, but you can also add each one to the prototype if you want the nice chaining feature as well.
const Observable = require('@rxjs/rx/observable');// Add class methods Observable.addToObject({ fromArray: require('@rxjs/rx/observable/fromarray') });// Add instance methods Observable.addToPrototype({ filter: require('@rxjs/rx/observable/filter'), map: require('@rxjs/rx/observable/map') });const subscription = Observable.fromArray([1,2,3]) .filter(x =\> x % 2 === 0) .map(x =\> x + 2) .subscribe(x =\> console.log(`The answer is ${x}`));
๐ In addition, we also added some distributions that you will find under our
src/modular/dist
folder which contains all of RxJS built in a UMD style as well as a "lite" version as well. This should give you the building blocks for creating your own builds of RxJS and taking the only the operators you need.โ Adding
repeatWhen
We often try to keep parity with other Rx versions such as RxJava. To that end, we've added
repeatWhen
which complements theretryWhen
we've had for quite some time. Rather than buffering and replaying the sequence from the source Observable, therepeatWhen
resubscribes to and mirrors the source Observable, but only conditionally based upon the Observable you return from the call.Here is an example where we can repeat a sequence twice with a delay of 200ms in between time.
const source = Rx.Observable.just(42) .repeatWhen(function(notifications) { return notifications.scan((acc, x) =\> return acc + x, 0) .delay(200) .takeWhile(count =\> count \< 2); });var subscription = source.subscribe( x =\> console.log(`Next ${x}`, err =\> console.log(`Error ${err}`), () =\> console.log('Completed') );// =\> Next: 42// 200 ms pass// =\> Next: 42// 200 ms pass// =\> Completed
Parity with RxJS v5 names
Given the differences between RxJS v4 and RxJS v5, we've made the migration path easier by creating aliases for you such as the following:
// Prototype methodsObservable.prototype.race = Observable.prototype.amb;Observable.prototype.mergeMap = Observable.prototype.flatMap;Observable.prototype.switchMap = Observable.prototype.flatMapLatest;Observable.prototype.exhaustMap = Observable.prototype.flatMapFirst;Observable.prototype.exhaust = Observable.prototype.switchFirst;Observable.prototype.publishReplay = Observable.prototype.replay;// Object methodsObservable.bindCallback = Observable.fromCallback;Observable.bindNodeCallback = Observable.fromNodeCallback;Observable.race = Observable.amb;
Other Changes
- ๐ Bug fixes such as to
ConnectableObservable
so that if the underlyingSubject
has been disposed, we will no longer attempt to resubscribe to it. - โฑ The
startWith
operator no longer usesScheduler.currentThread
and now usesScheduler.immediate
, as that caused issues with the backpressure operators such aspausable
andpausableBuffered
. - ๐ Documentation bug fixes
- ๐ Build What You Want with
Previous changes from v4.0.6
-
๐ This is a bug fix release of the Reactive Extensions for JavaScript (RxJS) for version 4.0 to fix a number of issues. The most prominent being the issue with
fromPromise(promise)
was swallowing errors fromObservable
instances which is now fixed. Looking forward, we will continue to work on performance as well as the modular design for those who want to pick and choose which pieces from NPM they want to use.๐ Performance Work
๐ Work continued on performance with
Rx.Observable.onErrorResumeNext
,Rx.Observable.mergeDelayError
as well as our join patterns. Expect this to continue throughout the lifecycle of v4.x.๐ Bugs Fixed:
๐ These were the bugs fixed during this release since 4.0.0:
- โฑ #969 - fix for
timeout
without otherObservable
- โ
#964 - fixed shared state for
zip
,combineLatest
andwithLatestFrom
insubscribeCore
- ๐ #963 - Angular broken with latest release
- #957 - fix issue with
fromEvent
not firing - #955 -
rx.d.ts
compilation issue fix - #949 - add null handling for
isIterable
check - #947 - add
initialValue
topublishValue.md
- #941 - fix for
timer
which was firing immediately - ๐ #939 - documentation fix for
find
- 0๏ธโฃ #938 - fix
defaultIfEmpty
with default value. - #936 - fix
fromPromise
behavior not to swallow errors when used withRx.Observable.spawn
- #934 - fix
BehaviorSubject
inheritance fromObserver
- #932 - include
zip
in TypeScript exports - ๐ #931 - include
merge
in TypeScript exports
- โฑ #969 - fix for