npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rxjs-compatibility

v0.0.3

Published

Use RxJS v5 with v4 and vice versa

Downloads

282

Readme

rxjs-compatibility

Convert Observables from RxJS v5 to v4 and vice versa.

Please upgrade to 100% RxJS v5 ASAP

This library is meant as a stop gap to help ease migration progressively, not as a band-aid for indefinite interop.

Install

This has a peer dependencies of rxjs@5.*.* and rx@4.*.*, which will have to be installed as well.

npm install --save rxjs-compatibility

Usage

Note: this library does not provide automatic interop between the two for cases like ObservableV4.from(v5), v4.flatMap(() => v5), etc. You must explicitly "convert" between the two.

When you convert from one Observable version to the other, keep in mind that if it's currently in v4 "mode", you'll only have v4 operators until you convert it back to v5 and vice versa. Effectively the result of one is piped into the other, just like how normal operators work.

Operators

The most ergonomic way to convert between the two versions is via the included operators patched on both Observable prototypes.

At some entry point file, you first run this to patch them:

import { patchObservables } from 'rxjs-compatibility';

patchObservables();

If you need to customize what Observable prototypes get patched, you can optionally provide them as v4 and v5 arguments:

patchObservables(ObservableV4, ObservableV5);

This is usually only neccesary when you're not using CommonJS modules. e.g. UMD builds of v4 and v5 use the same global variable window.Rx so you need to store them elsewhere and then provide them to the patchObservable call.

stream$.v4()

Converts the current Observable to a v4 Observable. Exists and works on both v5 Observables and ones that are already v4 too, in which case they just return this.

RxV5.Observable.of(1, 2, 3)
  .v4()
  .select(num => num + 1)
  .subscribe(value => console.log(value));

// 2, 3, 4

stream$.v5()

Converts the current Observable to a v5 Observable. Exists and works on both v4 Observables and ones that are already v5 too, in which case they just return this.

RxV4.Observable.of(1, 2, 3)
  .v5()
  .map(num => num + 1)
  .subscribe(value => console.log(value));

// 2, 3, 4

Demo

You can give it a spin in JSBin: http://jsbin.com/foqara/edit?js,output

Notice that because JSBin doesn't support a module system and instead uses global variables, you have to provide the Observable classes you want to patch.

Utility helpers

If you need to convert an existing observable and don't want to (or can't) patch the prototype, you can use the provided helpers:

import { toV4, toV5 } from 'rxjs-compatibility';

const v5 = ObservableV5.of(1, 2, 3);

toV4(v5) instanceof ObservableV4;
// true