Replace Producer concept with (ES or RxJS) Observable
See original GitHub issueXstream is hot streams only, but in rare cases we need cold streams. @TylorS had experienced this hard limitation in a convincing use case. We were discussing what alternative solutions do we have, and we landed on one very interesting possible solution: to replace Producers in xstream with typical Observables.
That would mean dropping the {start, stop}
API for a familiar subscribe
+ subscription.unsubscribe
API. It means everywhere where we expect a Producer, we would expect a cold Observable, e.g. xs.create(observable)
, where observable
is an object with a subscribe(observer)
function.
This would enable also very interesting interop with RxJS, because we could do xs.create(Rx.Observable.of(1,2,3))
for instance. The only requirement that we have from obs
in xs.create(obs)
would be that it’s an object with subscribe(observer)
function. Alternatively, we could also support the API xs.create(subscribe)
where subscribe
is the function subscribe(observer)
. So the type signature for create
would be:
type Subscribe<T> = (observer: Observer<T>) => Subscription;
interface Observable<T> {
subscribe: Subscribe<T>;
}
function create<T>(o: Observable<T> | Subscribe): Stream<T>;
In essence, xs.create
would behave like a multicast in RxJS, with the additional effect of converting from cold world to hot world permanently, since we don’t have a conversion path from xs.Stream => Observable.
This is for now very experimental, @TylorS will give it a try. He’s going to build it as an experiment in a PR. It would affect a lot of the current infrastructure in xstream, and would mean a breaking change, but for most xstream/Cycle.js users there wouldn’t be any noticeable changes if they are using streams created in drivers and just using operators inside main()
.
Anyone else wants to give their opinion about this? Any foreseeable problems that I haven’t mentioned? @Widdershin @Hypnosphi @laszlokorte @blesh
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
Top GitHub Comments
@staltz you don’t really even have to…
Rx.Observable.from(reduxStore)
actually works. Redux stores implement[Symbol.observable]()
.I think this is a good idea, because it would enable interop with more libraries than just RxJS. Most streams, or even a Redux store could be used as a producer.