Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/web-mech/can-stream-x

Stream values into and out of computes
https://github.com/web-mech/can-stream-x

baconjs can-stream canjs kefir rxjs stream

Last synced: 24 days ago
JSON representation

Stream values into and out of computes

Awesome Lists containing this project

README

        

# can-stream-x

[![Build Status](https://travis-ci.org/web-mech/can-stream-x.svg?branch=master)](https://travis-ci.org/web-mech/can-stream-x)

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
```