Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
any-observable
Advanced tools
Package description
The any-observable package allows you to register an Observable library of your choice and use it throughout your application as a singleton. This means you can use Observables without being locked into a specific library, providing flexibility in your codebase.
Registering a specific Observable implementation
This feature allows you to register an Observable implementation that will be used whenever you import 'any-observable'.
const anyObservable = require('any-observable');
anyObservable.register('rxjs'); // or 'zen-observable', etc.
Using the registered Observable
Once an Observable library is registered, you can create and use Observables as you would normally with that library.
const Observable = require('any-observable');
const stream = new Observable(observer => {
observer.next('Hello, World!');
observer.complete();
});
stream.subscribe({
next: console.log,
complete: () => console.log('Stream finished')
});
RxJS is a library for reactive programming using Observables. It provides more functionality out of the box compared to any-observable, which is a wrapper to use any Observable implementation.
Zen Observable is a minimalistic library for Observables. It is smaller and has fewer features than RxJS, but can be used with any-observable to provide a consistent Observable interface.
Observable-fns is a lightweight Observable library that focuses on core functionality. It is similar to zen-observable and can also be used with any-observable.
Readme
Support any Observable library and polyfill
Like any-promise
. (Docs are lacking here, so refer to those docs for now)
$ npm install any-observable
You must also install the Observable library you want:
$ npm install zen-observable
const Observable = require('any-observable'); // Using `zen-observable` since it's installed
Observable.of(1, 2).forEach(value => {
console.log(value);
});
//=> 1
//=> 2
This adds the following shortcut registrations:
rxjs-min
: Bare bones RxJs Observable implementation. See the RxJs Installation Instructions for details on patching additional methods into that implementation.rxjs
: Same as rxjs-min
, but adds the somewhat standard Observable.of
and Observable.from
.rxjs-all
: The kitchen sink approach to Observables.zen
: The zen-observable
implementation.Shortcut registration can be done as follows:
import 'any-observable/register/zen';
It's especially handy for more recent versions of Node.js (and many test runners), that offer a --require
flag:
$ ava --require=any-observable/register/zen test.js
FAQs
Support any Observable library and polyfill
The npm package any-observable receives a total of 1,404,375 weekly downloads. As such, any-observable popularity was classified as popular.
We found that any-observable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.