Member-only story
RxJS: Avoiding rxjs-compat
Introducing unintentional dependencies on rxjs-compat
is something that I see developers doing every now and then. Let’s have a look at rxjs-compat
to see what it is, how it works and how depending upon it can be avoided.
If you’re only interested in avoiding the dependency, skip to the TL;DR at the bottom of the article.
So what is it?
In RxJS version 6, breaking changes made the library simpler:
- the prototype-patching operators were removed; and
- the export locations were rearranged so that each export was available from only a single location.
Those changes made the library easier to maintain, document and explain, but they created a burden for developers with large RxJS-version-5 codebases: pretty much all RxJS-related code would need to be modified.
The rxjs-compat
package was created so that developers could upgrade to RxJS version 6 without having to modify code. It re-implements the prototype-patching operators and makes available all of the RxJS-version-5 export locations.
How does it work?
The RxJS-version-6 distribution includes files for all of the version-5 export locations. However, the imports within those files redirect to rxjs-compat
.