🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

callbag-from-obs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callbag-from-obs

Convert an observable to a callbag listenable source

1.2.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

/**

  • callbag-from-obs
  • Convert an observable (or subscribable) to a callbag listenable source.
  • npm install callbag-from-obs
  • Example:
  • Convert an RxJS Observable:
  • const Rx = require('rxjs');
    
  • const fromObs = require('callbag-from-obs');
    
  • const observe = require('callbag-observe');
    
  • const source = fromObs(Rx.Observable.interval(1000).take(4));
    
  • observe(x => console.log(x)(source); // 0
    
  •                                      // 1
    
  •                                      // 2
    
  •                                      // 3
    
  • Convert anything that has the .subscribe method:
  • const fromObs = require('callbag-from-obs');
    
  • const observe = require('callbag-observe');
    
  • const subscribable = {
    
  •   subscribe: (observer) => {
    
  •     let i = 0;
    
  •     setInterval(() => observer.next(i++), 1000);
    
  •   }
    
  • };
    
  • const source = fromObs(subscribable);
    
  • observe(x => console.log(x))(source); // 0
    
  •                                       // 1
    
  •                                       // 2
    
  •                                       // 3
    
  •                                       // ...
    

*/

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

const fromObs = observable => (start, sink) => { if (start !== 0) return; let dispose; sink(0, t => { if (t === 2 && dispose) { if (dispose.unsubscribe) dispose.unsubscribe(); else dispose(); } }); observable = observable[$$observable] ? observable$$observable : observable; dispose = observable.subscribe({ next: x => sink(1, x), error: e => sink(2, e), complete: () => sink(2) }); };

module.exports = fromObs;

Keywords

callbag

FAQs

Package last updated on 04 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts