-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Compose subscriptions in single operation #1583
Comments
I'm not sure if I understood correctly (please point me if I'm wrong), is this means flowwise similar as below? (pseudo, course) const existingSubs:Array<Subscription> = [....];
const sub = new Subscription();
existingSubs.forEach(x => sub.add(x)); |
Yup! Just a way to do that with a single expression/function call. |
I'd consider this could be achieved relatively short code externally, without introducing additional interface to subscription. Would you able to elaborate use case bit more? |
Yes, this is definitely a convenience. For use cases, you can check out how we use Atom/event-kit's new CompositeDisposable(
a.subscribe(...),
b.subscribe(...),
c.subscribe(...),
); Often, this is used as an argument to another function, e.g. doSomething(
new CompositeDisposable(
...
),
); It's certainly possible to do this by iterating over a list of subscriptions and adding them, but not nearly as elegant. At first I thought that I could achieve something similar by chaining |
I will not conclude this by myself and would like to wait other suggestions as well - as implementation itself is somewhat trivial only concern I'm having is api surface to |
Current possible solutionsTechnically, right now you could do Also, right now you could do this: ProposalWe could have new Subscription(someUnsubFunc, subscription1, subscription2); The risk here is that Subscription becomes too polymorphic and it negatively impacts performance. Another risk is that the implementation inefficiently allocates an array or other resources before it has to. |
Yeah, this was actually the source of a pretty nasty bug of mine! I had assumed that The constructor option would definitely be the least surprising API IMO but like I mentioned in the OP, |
Summary:This change upgrades us to the RxJS 5 beta. It includes: * Update Flow definitions to reflect new APIs * Add `DisposableSubscription` and `CompositeSubscription` for dealing with new Subscription API (See also ReactiveX/rxjs#1583) * Add `bufferUntil` to replace some `buffer()` usages (See ReactiveX/rxjs#1610) * Remove rx-dom * Update package.json * Update all code to use new APIs Reviewed By: peterhal Differential Revision: D3131543 fb-gh-sync-id: 437c7b90d6e1fd8e463a57eb341146bbc4e9bbd3 fbshipit-source-id: 437c7b90d6e1fd8e463a57eb341146bbc4e9bbd3
Before going to ask in the wild, I thought to quickly try here. Sorry if this is a little bit off-topic. Does anyone know how to extend let rootSubscription = new Subscription();
someObservable$
.subscribe(someValue => doSomething(someValue))
.addTo(rootSubscription);
anotherObservable$
.subscribe(anotherValue => doSomethingElse(anotherValue))
.addTo(rootSubscription);
function addTo(
collectorSub: Subscription, // this is the explicit parameter
thisSub: Subscription // this is the "implicit" instance
): void {
collectorSub.add(thisSub);
} Thanks, and sorry again for temporarily diverting this issue. |
closing this as inactive. Feel free to reopen if needed. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Small feature request:
I'd like a way to compose multiple subscriptions in a single operation. Something like
Subscription.create(...subscriptions: Array<Subscription>): Subscription
. (I'm assuming that the constructor doesn't do this for perf reasons, so supporting var-args inadd
would be my second choice.)If this is something that would be merged, I can put together a PR.
The text was updated successfully, but these errors were encountered: