Changelog History
-
v4.1.0 Changes
March 07, 2016๐ 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
-
v4.0.8
February 17, 2016 -
v4.0.7
November 13, 2015 -
v4.0.6 Changes
October 14, 2015๐ 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
-
v4.0.5
October 13, 2015 -
v4.0.3
October 13, 2015 -
v4.0.2
October 13, 2015 -
v4.0.1
October 08, 2015 -
v4.0.0 Changes
September 26, 2015๐ This is another release in terms of cleaning up our technical debt by simplifying a number of our infrastructure, including our schedulers both for regular usage as well as testing. There were will be a few more point releases from this repository before a switch over the more modern RxJS vNext, including modularity, expression trees, and so forth.
๐ Before we go further, it's worth mentioning that since Microsoft Edge supports ES 2016 Async Functions, you can take advantage of them in whole new ways in RxJS, because as we've had support for returning Promises, we support async functions as well.
With a very quick example, we can do the following:
const source = Rx.Observable.of(1,2,3) .flatMap(async function (x, i) { var result = await Promise.resolve(x \* i); return result; });source.subscribe((x) =\> console.log(`Next: ${x}`))// =\> Next: 0// =\> Next: 2// =\> Next: 6
๐ Included in this release are the following:
- A More Complete
rx.all.js
- โฑ Scheduler rewrite
- โ Testing rewrite
- Collapsing of operators
- ๐ Performance upgrades
๐ What's coming next in this release?
- Modularity
- ๐ More Performance Upgrades
A More Complete
rx.all.js
๐ In previous releases,
rx.all.js
and its compat counterpartrx.all.compat.js
contained all of the operators in RxJS, but did not include any of the testing infrastructure. This has been changed so that you no longer need to bring inrx.testing
in order to write your own tests.โฑ Scheduler Rewrite
โฑ The schedulers have long had a long of technical debt when brought over directly from the .NET world. To simplify this, we will now have the following contract on the
Scheduler
as written in TypeScript so that it makes sense as an interface. You will notice that the previous versions which did not have state associated with them are no longer supported. This caused too much overhead to support both, so if you have no state to pass, simply passnull
for the state.interface IDisposable { dispose(): void}interface IScheduler { // Current time now(): number; // Schedule immediately schedule\<TState\>(state: TState, action: (scheduler: IScheduler, state: TState) =\> IDisposable) : IDisposable; // Schedule relative scheduleFuture\<TState\>(state: TState, dueTime: number, action: (scheduler: IScheduler, state: any) =\> IDisposable) : IDisposable; // Schedule absolute scheduleFuture\<TState\>(state: TState, dueTime: Date, action: (scheduler: IScheduler, state: TState) =\> IDisposable) : IDisposable; // Schedule recursive scheduleRecursive\<TState\>(state: TState, action: (state: TState, action: (state: TState) =\> void) =\> void): IDisposable; // Schedule recursive relative scheduleRecursiveFuture\<TState\>(state: TState, dueTime: number, action: (state: TState, action: (state: TState, dueTime: number) =\> void) =\> void): IDisposable; // Schedule recursive absolute scheduleRecursiveFuture\<TState\>(state: TState, dueTime: Date, action: (state: TState, action: (state: TState, dueTime: Date) =\> void) =\> void): IDisposable; // Schedule periodic schedulePeriodic\<TState\>(state: TState, period: number, action: (state: TState) =\> TState): IDisposable; }
โฑ Now, to schedule something immediately, you must follow the following code snippet. The return value is optional as we will automatically fix it to be a
Disposable
if you do not provide us with one.var d = scheduler.schedule(null, function (scheduler, state) { console.log('scheduled ASAP'); return Rx.Disposable.empty; });
โฑ Same applies to scheduling in the future:
// Scheduled 5 seconds in the future with absolute timevar d = scheduler.scheduleFuture(null, new Date(Date.now() + 5000), function (scheduler, state) { console.log('scheduled using absolute time'); return Rx.Disposable.empty; });// Scheduled 5 seconds in the future with relative timevar d = scheduler.scheduleFuture(null, 5000 function (scheduler, state) { console.log('scheduled using relative time'); return Rx.Disposable.empty; });
โฑ You will also notice that the recursive scheduling as well as periodic scheduling removed the versions where no state was involved. Also, it is necessary to enforce that with
scheduleRecursiveFuture
determines the relative or absolute timing by the return value from therecurse
call for example. If you don't wish to use state for therecurse
call, simply userecurse(null, dueTime)
.// Absolute schedulingscheduler.scheduleRecursiveFuture(1, new Date(Date.now() + 5000), function (state, recurse) { if (state \< 10) { recurse(state + 1, new Date(Date.now() + (state \* 1000)); } });// Relative schedulingscheduler.scheduleRecursiveFuture(1, 5000, function (state, recurse) { if (state \< 10) { recurse(state + 1, state \* 1000); } });
โ Testing Rewrite
๐ One of the biggest undertakings in this release was to standardize and clean up our unit tests. Over the past releases, there was a bit of technical debt that needed to be paid off. In this release, our virtual time system as well as our test scheduling was rewritten as to put it more in line with the regular schedulers. We rid ourselves of the
WithState
operators, simply renaming them to their basic operators such asscheduleAsbolute
andscheduleRelative
.โฑ With the
TestScheduler
, we cleaned it up so that you can easily specify when a particular timing for the creation, subscription and disposal of the Observable sequence. This is a quick example of a test in action using timing where in thescheduler.startScheduler
method as the second parameter, you can pass in an object with some timings for creation, subscription disposal. If you omit this, it will default to the normal timings of100
forcreated
,200
forsubscribed
and1000
fordisposed
.test('first default', function () { var scheduler = new TestScheduler(); var xs = scheduler.createHotObservable( onNext(150, 1), onCompleted(250) ); var res = scheduler.startScheduler( function () { return xs.first({defaultValue: 42}); }, { created: 100, subscribed: 200, disposed: 1000 } ); res.messages.assertEqual( onNext(250, 42), onCompleted(250) ); xs.subscriptions.assertEqual( subscribe(200, 250) ); });
โ All tests should look like this now making them much easier to read going forward.
Collapsing of Operators
โฑ Previously, we had a number of operators such as
debounceWithSelector
andtimeoutWithSelector
that were simply overloads of their respectivedebounce
andtimeout
methods. To avoid confusion having more named operators, we have simply condensed those intodebounce
and timeout` so that they look like the following:Debounce with relative due time:
โฑRx.Observable.prototype.debounce(dueTime, [scheduler])
Debounce with selector:
Rx.Observable.prototype.debounce(durationSelector)
โฑ Timeout with relative or absolute due time:
โฑRx.Observable.prototype.timeout(dueTime, [other], [scheduler])
โฑ Timeout with selector and optional first timeout:
โฑRx.Observable.prototype.timeout([firstTimeout], timeoutDurationSelector, [other])
๐ Performance Upgrades
๐ In this version, we addressed more performance as we rewrote many operators to minimize chained scopes in addition to writing operators from the bottom up instead of relying on composition from other operators. This had some significant increases in some areas. In addition, we also did some shortcuts for example if the
Rx.Scheduler.immediate
was used, we could swap that out for an inline call with returning an empty disposable.๐ In RxJS vNext, many of the performance concerns will be addressed and have shown great progress.
What's Next
๐ There will be a number of more releases for 4.x until vNext is ready which will address a number of issues including:
- Modularity
- ๐ Performance
Modularity
๐ Now that the operators and schedulers have largely stabilized for performance, we're going to fix more of the modularity story, allowing you to bring in only what you need. Work had already begun on this part of the project, but now that the majority of the technical debt has been paid, this makes for a much easier transition.
๐ Performance
๐ Although many operators have been rewritten to minimized chained scopes, there are a number of operators that have not. In this release, we intend to get those operators such as
timeout
to be optimized for performance and making it more optimized for the GC. - A More Complete
-
v3.1.2
August 31, 2015