Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for subscribing other callbags #10

Open
loreanvictor opened this issue Oct 16, 2020 · 5 comments
Open

Support for subscribing other callbags #10

loreanvictor opened this issue Oct 16, 2020 · 5 comments

Comments

@loreanvictor
Copy link

In RxJS, you can call .subscribe() on any Observer, including other Subjects for example. In callbag world, any callbag can be an observer as well, so it would make sense to add support for subscribing other callbags directly. This way, you could invoke subscribe() on callbag subjects for example, mirroring similar behavior in RxJS.

Here is a sample of how that would work. I could make a PR directly, but wanted to ensure that this is something that you do want to add before writing tests for it.

@loreanvictor
Copy link
Author

@zebulonj any thoughts?

@zebulonj
Copy link
Owner

This slipped through my radar. Thanks for re-upping it. I'll give it some thought today.

@loreanvictor
Copy link
Author

@zebulonj may I bump this again? 😅

@zebulonj
Copy link
Owner

Ok. I follow your inquiry. When you say "support for subscribing other callbags directly" you're referring to the subject (for example) as a sink:

import makeSubject from 'callbag-subject';
import interval from 'callbag-interval';
import pipe from 'callbag-pipe';

import subscribe from './subscribe';

const sub = makeSubject();

pipe(
  interval(1000),
  subscribe(sub)
);

I've wrestled with this on my own. Superficially, it's a nice pattern. I find myself hesitating though when considering that without intermediating logic, this suggests that not only data, but also errors and completions would be passed to the target subject. Have you thought through the consequences of that? If the source to which the subject subscribes using your proposed overloading encounters an error, what should happen to the subject? Downstream from the subject?

Have you thought about how you'd implement this overloading safely?

@loreanvictor
Copy link
Author

I was thinking of treating given Callbag as a sink, which means passing down errors, termination signals, etc. This is perfectly mirroring the same behavior in RxJS, where a Subject can be treated as an Observer, and hence can be passed to .subscribe() method of any Observable. In that case, it would also receive completion signals or errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants