symbol-observable
Symbol.observable ponyfill
Last updated a month ago by blesh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install symbol-observable 
SYNC missed versions from official npm registry.

symbol-observable Build Status

Symbol.observable ponyfill

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

Current Tags

  • 3.0.0                                ...           latest (a month ago)

18 Versions

  • 3.0.0                                ...           a month ago
  • 2.0.3                                ...           2 months ago
  • 2.0.2                                ...           2 months ago
  • 2.0.1                                ...           3 months ago
  • 2.0.0                                ...           3 months ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 0.2.4                                ...           5 years ago
  • 0.2.3                                ...           5 years ago
  • 0.2.2                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 20,123
This Week 20,123
This Month 497,130
Last Day 6,402
Last Week 122,606
Last Month 386,217
Dependencies (0)
None
Dev Dependencies (7)
Dependents (344)

Copyright 2014 - 2016 © taobao.org |