npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

symbol-observable

v4.0.0

Published

Symbol.observable ponyfill

Downloads

63,358,620

Readme

symbol-observable Build Status

Symbol.observable pony/polyfill

This will polyfill Symbol.observable if Symbol exists, but will not polyfill Symbol if it doesn't exist. Meant to be used as a "ponyfill", meaning you're meant to use the module's exported symbol value as described below. This is all done to ensure that everyone is using the same version of the symbol (or string depending on the environment), as per the nature of symbols in JavaScript.

Install

$ npm install --save symbol-observable

Basic Usage

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

console.log(symbolObservable);
//=> Symbol(observable)
import Symbol_observable from 'symbol-observable';

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

Making an object "observable":

You can do something like what you see below to make any object "observable" by libraries like RxJS, XStream and Most.js.

Things to know:

  1. It's best if you just use one of the above libraries.
  2. If you're not, but sure you never next, error or complete on your observer after error or complete was called.
  3. Likewise, make sure you don't next, error or complete after unsubscribe is called on the returned object.
import Symbol_observable from 'symbol-observable';

someObject[Symbol_observable] = () => {
  return {
    subscribe(observer) {
      const handler = e => observer.next(e);
      someObject.addEventListener('data', handler);
      return {
        unsubscribe() {
          someObject.removeEventListener('data', handler);
        }
      }
    },
    [Symbol_observable]() { return this }
  }
}

Often, it's not very hard, but it can get tricky in some cases.

Related

License

MIT © Sindre Sorhus and Ben Lesh