A Breakdown of RxJS 7.0 Performance Improvements
It’s official.
RxJS 7.0 has been deemed stable and is now available in its beta form.
The core team, committed to maintaining a dependable and adaptable reactive programming tool, has built this new release to improve many aspects of developer experience without triggering changing breaks to existing code.
Through a partnership with Google, the RxJS core team was able to test its latest release by integrating the library into the Google 3 monorepository. In doing so, they ran RxJs against thousands of build targets, and across countless applications, to identify where code breaks were happening, and what could be done to ensure stronger stability.
Updated Typing
RxJS 7.0 is written in Typescript 3.8, which allows users to leverage all of Typescript’s latest features. For example, RxJS’ typing inference capacity, especially with respect to how the library handles generics, has significantly improved. Previous versions struggled to type larger rests of arguments, with prior upper bound limits not usually exceeding 8 or 9 values. These limitations, however, have been removed, allowing developers to pass an infinite number of values with one call.
The team was also able to fix many antiquated types that did not reflect the runtime behavior of actual APIs. As a result, several Observables, including *'toPromise()'*, have been deprecated in order to mitigate the challenges of legacy behavior without significantly impacting existing code.
New Features
animationFrames(): an Observable that returns the milliseconds elapsed since the start of the Observable, which is especially useful for coding animation, and replaces previous methods of incrementing numbers.
lastValueFrom() and firstValueFrom(): Observables that return the last and first values in a promise, respectfully. They improve upon *‘toPromise()’* by returning an ‘EmptyError’ when passing promises without values, and giving users more flexibility when selecting the values they want returned.
AsyncIterable support: Any areas of code that previously accepted a Promise, or an Observable, now also accept AsyncIterables.
rxjs-for-await: a separate library which supports async-await for-await loops via AsyncIterables.
*'retry({resetOnSuccess: true})'*: In 6.0, if you had a source that errored with, for example, a retry count valued at 5, it would only error a total of 5 times, no matter how many successful messages it had passed. With *'retry({resetOnSuccess: true})'*, the retry count value will reset every time a successful message is passed.
TimeStamp: an interface with a *‘now()’* method that returns a number.
Name Changes: In order to create fewer collisions between four legacy operators, and creation methods with the same name...
*'zip(other$)'* is now *'zipWith(other$)'*.
*'combineLatest(a$, b$)'* is now *'combineLatestWith(a$, b$)'*.
*'merge(partner$)'* is now 'mergeWith(partner$)'.
*'concat(ender$)'* is now *'concatWith(ender$)'*.
Deprecations
In 7.0, no critical elements have been removed from the library, but several features have been deprecated. These include:
ResultSelectors, which have been deprecated since 5.0.
The process of passing scheduler arguments through functions such as ‘of()’ or ‘range()’ has been deprecated, and should be replaced by using ‘scheduled()’ or ‘observeOn()’. This has been done in order to remove scheduling logic from operators that don’t need it.
Some subscription signatures will be deprecated. With this newest release, subscriptions should only be called with a single function, or a partial or complete Observable. The same will also go for tap signatures. This will simplify the development process and help eventually make the library more lean with future releases.
Functions that pull in schedulers are now deprecated as of this release in order to prepare users for the eventual phase-out of passing schedulers to certain functions.
Looking Forward to 7.1 and Beyond
In order to support future changes to the library, the RxJS team will begin introducing ESLint transformations. These updates will help developers remove deprecated code, such as APIs, from their applications, and prepare users for future, major releases as the library becomes faster and leaner. However, Ben Lesh, RxJS core team lead, ensures that no breaking changes will be scheduled until version 9.0 at the earliest.
How You Can Contribute
The RxJS core team welcomes enthusiastic RxJS experts to help contribute to refining version 7’s future updates. Those experienced with ESLint transformations, or who want to update documentation are welcome to contribute to this open-source library.
And of course, the RxJS team relies on the amazing work of authors, bloggers, content creators, and those working in developer relations, to share insights into the library with the development community.
If you’re just getting started with RxJS, check out this fantastic “1 Hour to Learn RxJS” tutorial by Ben Lesh from This Dot Labs' Javascript Marathon, where you can learn about Observables and operators, including how to build an Observable from scratch!...