Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rxjs

Package Overview
Dependencies
Maintainers
3
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rxjs

Reactive Extensions for modern JavaScript

  • 7.8.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
41M
decreased by-18.28%
Maintainers
3
Weekly downloads
 
Created

What is rxjs?

RxJS (Reactive Extensions for JavaScript) is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code. It provides an API for asynchronous programming with observable streams.

What are rxjs's main functionalities?

Creating Observables

This feature allows you to create an Observable stream of data. The code sample demonstrates how to create an Observable that emits several values over time.

const { Observable } = require('rxjs');

const observable = new Observable(subscriber => {
  subscriber.next(1);
  subscriber.next(2);
  subscriber.next(3);
  setTimeout(() => {
    subscriber.next(4);
    subscriber.complete();
  }, 1000);
});

Subscribing to Observables

This feature allows you to subscribe to an Observable and react to the data being emitted. The code sample shows how to subscribe to an Observable created from an array.

const { from } = require('rxjs');

const observable = from([10, 20, 30]);
const subscription = observable.subscribe(x => console.log(x));

Operators

Operators are methods on the Observable type that allow for composing asynchronous operations in a declarative manner. The code sample demonstrates the use of 'filter' and 'map' operators to process data.

const { of } = require('rxjs');
const { map, filter } = require('rxjs/operators');

const nums = of(1, 2, 3, 4, 5);
const squaredNums = nums.pipe(
  filter(n => n % 2 !== 0),
  map(n => n * n)
);
squaredNums.subscribe(x => console.log(x));

Handling Errors

This feature allows you to handle errors in an Observable sequence. The code sample demonstrates how to catch and handle errors using the 'catchError' operator.

const { throwError, of } = require('rxjs');
const { catchError } = require('rxjs/operators');

const observable = throwError(new Error('Something went wrong!'));
const handled = observable.pipe(
  catchError(error => of(`Caught: ${error.message}`))
);
handled.subscribe(x => console.log(x), err => console.error(err));

Combining Observables

This feature allows you to combine multiple Observables into one. The code sample demonstrates how to use 'combineLatest' to combine two streams of data.

const { combineLatest, of } = require('rxjs');

const temperature = of(70, 72, 76, 79, 75);
const humidity = of(40, 44, 49, 58, 55);

const combined = combineLatest([temperature, humidity]);
combined.subscribe(([temp, hum]) => console.log(`Temperature: ${temp} Humidity: ${hum}`));

Other packages similar to rxjs

Keywords

FAQs

Package last updated on 26 Apr 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc