symbol-observable

WebJar for symbol-observable

License

License

MIT
Categories

Categories

Github Development Tools Version Controls
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

github-com-benlesh-symbol-observable
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

symbol-observable
WebJar for symbol-observable
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/benlesh/symbol-observable

Download github-com-benlesh-symbol-observable

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/github-com-benlesh-symbol-observable/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>github-com-benlesh-symbol-observable</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/github-com-benlesh-symbol-observable/
implementation 'org.webjars.npm:github-com-benlesh-symbol-observable:1.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/github-com-benlesh-symbol-observable/
implementation ("org.webjars.npm:github-com-benlesh-symbol-observable:1.2.0")
'org.webjars.npm:github-com-benlesh-symbol-observable:jar:1.2.0'
<dependency org="org.webjars.npm" name="github-com-benlesh-symbol-observable" rev="1.2.0">
  <artifact name="github-com-benlesh-symbol-observable" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='github-com-benlesh-symbol-observable', version='1.2.0')
)
libraryDependencies += "org.webjars.npm" % "github-com-benlesh-symbol-observable" % "1.2.0"
[org.webjars.npm/github-com-benlesh-symbol-observable "1.2.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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

Versions

Version
1.2.0