can-stream-x

1.0.2 • Public • Published

can-stream-x

Build Status

Stream values into and out of computes using any streaming lib. Great for streaming libs that return emitters as a callback.

Syntax

canStreamX([options]);

Notes

  • Passing falsey values for the emitter flag makes indicates the emitter is a function and should be called directly.
  • Passing falsey values for the unsubscribe method indicates the unsubscribe method is derived from the subscribe method.

Options

  • streamConstructor - method necessary to create a stream.
  • emitMethod - Which method to use as the emitter.
  • on - Which method to use to subscribe.
  • off - Which method to use to unsubscribe.

Example Usage

Using RxJs

var canStreamX = require('./can-stream-x');
var Rx = require('rxjs');
var Observable = Rx.Observable;

var canStream = canStreamX({
    streamConstructor: Observable.create,
    emitMethod: 'next',
    on: 'subscribe',
    off: 'unsubscribe'
});

var c = compute(0);

var stream = canStream.toStream(c);

var computeVal;

stream.subscribe((newVal) => {
    computeVal = newVal;
});

c(1);

console.log(computeVal); //1

Using Kefir

var canStreamX = require('./can-stream-x');
var Kefir = require('kefir');
var canStream = canStreamX({
  streamConstructor: Kefir.stream,
  emitMethod: 'emit',
  on: 'onValue',
  off: 'offValue'
});
...

Using Bacon

var canStreamX = require('./can-stream-x');
var Bacon = require('bacon');
var canStream = canStreamX({
  streamConstructor: Bacon.fromBinder,
  on: 'onValue',
  off: false
});
...

testing

npm test

Package Sidebar

Install

npm i can-stream-x

Weekly Downloads

4

Version

1.0.2

License

MIT

Last publish

Collaborators

  • webmech