rx-injectable-observable
v3.0.0
Published
RxJS Observable to which you can inject other Observables.
Downloads
6
Maintainers
Readme
rx-injectable-observable
RxJS Observable to which you can inject other Observables.
Utility for Cycle.js framework. By Eryk Napierała.
Installation
npm install rx-injectable-observable
Usage
import Rx from 'rx';
import InjectableObservable from 'rx-injectable-observable';
let sum$ = InjectableObservable((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$ = new InjectableObservable((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.