symbol-observable
Advanced tools
Weekly downloads
Readme
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.
$ npm install --save symbol-observable
const symbolObservable = require('symbol-observable').default;
console.log(symbolObservable);
//=> Symbol(observable)
import Symbol_observable from 'symbol-observable';
console.log(Symbol_observable);
//=> Symbol(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:
next
, error
or complete
on your observer after error
or complete
was called.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.
MIT © Sindre Sorhus and Ben Lesh
Symbol.observable ponyfill
The npm package symbol-observable receives a total of 11,258,291 weekly downloads. As such, symbol-observable popularity was classified as popular.
We found that symbol-observable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 3 open source maintainers collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.