cyclejs-stream
v1.0.1
Published
Observable (events stream) to which you can inject another streams.
Downloads
27
Readme
cyclejs-stream
Observable (events stream) to which you can inject another streams.
Utility for Cycle.js framework.
Usage
import createStream from 'cyclejs-stream';
import Rx from 'rx';
let sum$ = createStream((x$, y$) =>
Rx.Observable.combineLatest(x$, y$,
(x, y) => x + y
)
);
sum$.subscribe((x) => {
assert(x, 15);
});
// you can inject dependencies before and after subscription
sum$.inject(
Rx.Observable.just(9),
Rx.Observable.just(6)
);
setTimeout(() => {
sum$.dispose(); // and after some time remove underlying subscriptions
}, 1000);
// you can also inject stream to itself
let double$ = createStream((x$) => x$.map((x) => x * 2));
double$.inject(double$.startWith(1));
double$.elementAt(4).subscribe((x) => {
assert.equal(x, 32);
});
Notes
Subscription and injection order doesn't matter, but if nothing was injected to the stream, subscription doesn't initialize anything. When dependencies are injected, but stream was not subscribed yet, nothing happens as well. When subscribed AND injected the first time, stream becomes hot observable - next subscriptions don't receive already emitted values.