Socket
Socket
Sign inDemoInstall

zen-observable-ts

Package Overview
Dependencies
Maintainers
4
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zen-observable-ts

An Implementation of ES Observables in Typescript


Version published
Weekly downloads
4.8M
increased by5.95%
Maintainers
4
Weekly downloads
 
Created

What is zen-observable-ts?

The zen-observable-ts package is a TypeScript implementation of the Observable pattern, which is used for handling asynchronous data streams. It provides a way to create, transform, and consume sequences of values over time, making it useful for scenarios such as event handling, data fetching, and reactive programming.

What are zen-observable-ts's main functionalities?

Creating an Observable

This feature allows you to create an Observable that emits a sequence of values. In this example, the Observable emits 'Hello' and 'World' before completing.

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

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 with map

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

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

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

const mappedObservable = observable.map(value => value * 2);

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

Filtering Observables with filter

This feature allows you to filter the values emitted by an Observable using the filter operator. In this example, only values greater than 1 are emitted.

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

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

const filteredObservable = observable.filter(value => value > 1);

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

Combining Observables with merge

This feature allows you to combine multiple Observables into a single Observable using the merge operator. In this example, the values from both observables are emitted in sequence.

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

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

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

const mergedObservable = Observable.merge(observable1, observable2);

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

Other packages similar to zen-observable-ts

FAQs

Package last updated on 15 Nov 2019

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