Socket
Socket
Sign inDemoInstall

rxjs-interop

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rxjs-interop

Observable interop helpers for RxJS


Version published
Weekly downloads
38K
increased by4.06%
Maintainers
1
Install size
26.6 kB
Created
Weekly downloads
 

Changelog

Source

2.0.0 (2021-10-30)

Breaking Changes

  • Update Subscribable so that it's compatible with RxJS. (0e8cee0).

<a name="1.0.3"></a>

Readme

Source

rxjs-interop

GitHub License NPM version Build status dependency status devDependency Status peerDependency Status

What is it?

A package that contains interop helper functions and types for use with RxJS.

Why might you need it?

Observables exist independently of RxJS. There are TC39 and WHATWG observable proposals. The helpers in this package make it easy to implement observables that will work with or without RxJS and will still play nice - with RxJS - if Symbol.observable is not configured.

For more information on RxJS interop, see this blog post.

This package has no dependency on RxJS and is small, but if you want to publish an interop package with no dependencies, just copy the license and the code from this project into yours.

Install

Install the package using NPM:

npm install rxjs-interop --save

Usage

Interop observables expose an observable factory via the Symbol.observable property, like this:

export const interop = {
  [Symbol.observable]: () => {
    return {
      subscribe(nextOrObserver, error, complete) {
        /* figure out whether it's a next callback or an observer */
        /* call observer methods */
        return () => { /* some teardown logic */ };
      }
    };
  }
});

For this to work with RxJS, the caller will need to initialize Symbol.observable - which makes things more complicated.

You can use the toObserver and patch helpers in this package to more easily implement subscribe and to make sure that the interop observable will work with RxJS without Symbol.observable having to be initialized:

import { patch, toObserver } from "rxjs-interop";

export const interop = patch({
  [Symbol.observable]: () => {
    return {
      subscribe(nextOrObserver, error, complete) {
        const observer = toObserver(nextOrObserver, error, complete);
        /* call observer methods */
        return () => { /* some teardown logic */ };
      }
    };
  }
});

patch can be passed either an interop observable instance or the constructor of an interop observable class - see the tests for usage.

For an example of how this package can be used to implement things that can be used with or without RxJS, check out Christoph Guttandin's subscribable-things.

Keywords

FAQs

Last updated on 30 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc