Socket
Socket
Sign inDemoInstall

symbol-observable

Package Overview
Dependencies
0
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    symbol-observable

Symbol.observable ponyfill


Version published
Weekly downloads
13M
decreased by-0.86%
Maintainers
3
Install size
11.0 kB
Created
Weekly downloads
 

Package description

What is symbol-observable?

The symbol-observable package is primarily used to polyfill the Observable symbol, which is a proposed addition to the ECMAScript standard. It allows JavaScript objects to be observable, meaning that other objects can subscribe to them and react to changes. This is particularly useful in reactive programming models and libraries, such as RxJS, where data streams and their transformations are a core concept.

What are symbol-observable's main functionalities?

Polyfill for Observable Symbol

This code demonstrates how to use the symbol-observable package to make an object observable. It defines a simple observable that emits 'hi' every second. An observer subscribes to this observable to log the emitted values. This showcases how symbol-observable can be used to implement the observer pattern in JavaScript.

"use strict";

const symbolObservable = require('symbol-observable').default;

console.log(typeof symbolObservable); // 'symbol' in environments with native Symbol support

const obj = {};
obj[symbolObservable] = function () {
  return {
    subscribe(observer) {
      const intervalID = setInterval(() => observer.next('hi'), 1000);

      return {
        unsubscribe() {
          clearInterval(intervalID);
        }
      };
    }
  };
};

const observable = obj[symbolObservable]();
const subscription = observable.subscribe({
  next(val) { console.log(val); },
  complete() { console.log('Done'); }
});

// Later:
// subscription.unsubscribe();

Other packages similar to symbol-observable

Changelog

Source

1.2.0 (2018-01-26)

Bug Fixes

  • TypeScript: Remove global Symbol declaration (427c3d7)
  • common js usage example (#30) (42c2ffa)

Features

  • bundlers: Add module and main entries in package.json (#33) (97673e1)

<a name="1.1.0"></a>

Readme

Source

symbol-observable Build Status

Symbol.observable ponyfill

Install

$ npm install --save symbol-observable

Usage

const symbolObservable = require('symbol-observable').default;

console.log(symbolObservable);
//=> Symbol(observable)

License

MIT © Sindre Sorhus and Ben Lesh

Keywords

FAQs

Last updated on 26 Jan 2018

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