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

zen-observable

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zen-observable

An Implementation of ES Observables

  • 0.10.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.3M
decreased by-4.51%
Maintainers
1
Weekly downloads
 
Created

What is zen-observable?

The zen-observable npm package provides an implementation of the Observable pattern, which is used for managing asynchronous data streams. It allows you to create, transform, and subscribe to data streams in a declarative manner.

What are zen-observable's main functionalities?

Creating an Observable

This feature allows you to create a new Observable instance. The observer object is used to emit values and signal completion. The subscriber receives these values and handles them accordingly.

const { Observable } = require('zen-observable');

const observable = new Observable(observer => {
  observer.next('Hello');
  observer.next('World');
  observer.complete();
});

observable.subscribe({
  next(value) { console.log(value); },
  complete() { console.log('Done'); }
});

Transforming Observables

This feature allows you to transform the data emitted by an Observable using operators like map. In this example, each value emitted by the original Observable is multiplied by 2.

const { Observable } = require('zen-observable');

const observable = new Observable(observer => {
  observer.next(1);
  observer.next(2);
  observer.next(3);
  observer.complete();
});

const transformed = observable.map(x => x * 2);

transformed.subscribe({
  next(value) { console.log(value); },
  complete() { console.log('Done'); }
});

Combining Observables

This feature allows you to combine multiple Observables into a single Observable. In this example, two Observables are combined and their values are emitted in sequence.

const { Observable } = require('zen-observable');

const observable1 = new Observable(observer => {
  observer.next('A');
  observer.complete();
});

const observable2 = new Observable(observer => {
  observer.next('B');
  observer.complete();
});

const combined = Observable.from([observable1, observable2]).flatMap(x => x);

combined.subscribe({
  next(value) { console.log(value); },
  complete() { console.log('Done'); }
});

Other packages similar to zen-observable

FAQs

Package last updated on 28 Nov 2022

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