question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace Producer concept with (ES or RxJS) Observable

See original GitHub issue

Xstream 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
benleshcommented, Jul 11, 2016

@staltz you don’t really even have to… Rx.Observable.from(reduxStore) actually works. Redux stores implement [Symbol.observable]().

1reaction
benleshcommented, Jul 11, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Observable - RxJS
RxJS introduces Observables, a new Push system for JavaScript. An Observable is a Producer of multiple values, "pushing" them to Observers (Consumers).
Read more >
BehaviorSubject vs Observable? - Stack Overflow
From my understanding, a BehaviorSubject is a value that can change over time (can be subscribed to and subscribers can receive updated results)....
Read more >
Understanding RxJS Observables and why you need them
In this post, we will see a thorough introduction to Observables, observers and subscriptions in RxJS in addition to the lifecycle process.
Read more >
RxJS: Observables, Observers and Operators Introduction
This “thing” is called a producer and is a source of values - perhaps from a click or input event in the DOM...
Read more >
Using observables to pass values - Angular
An observable can deliver multiple values of any type —literals, messages, or events, depending on the context. The API for receiving values is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found