0.0.3 • Public • Published


    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.


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

    npm install --save rxjs-compatibility


    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.


    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';

    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.


    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)
      .select(num => num + 1)
      .subscribe(value => console.log(value));
    // 2, 3, 4


    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)
      .map(num => num + 1)
      .subscribe(value => console.log(value));
    // 2, 3, 4


    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


    npm i rxjs-compatibility

    DownloadsWeekly Downloads






    Last publish


    • jayphelps