Skip to content
Symbol.observable ponyfill
Branch: master
Clone or download
joshburgess and benlesh Typo fix (#39)
symbolObservable -> Symbol_observable
Latest commit e56e765 May 25, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
es feat(browser): Fully qualified import for native esm browser support (#… Nov 28, 2017
.travis.yml chore(publish): 1.2.0 Jan 26, 2018
index.js fix(bundlers): fix issue that caused some bundlers not to be able to … Jun 15, 2016
package-lock.json chore(publish): 1.1.0 Nov 28, 2017
package.json chore(publish): 1.2.0 Jan 26, 2018

symbol-observable Build Status

Symbol.observable ponyfill


$ npm install --save symbol-observable

Basic Usage

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

//=> Symbol(observable)
import Symbol_observable from '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 =>;
      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.



MIT © Sindre Sorhus and Ben Lesh

You can’t perform that action at this time.