refactor(subscribeToObservable): use subscribeWith util #5333
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR refactors the fix to #5051 that was made in #5059.
Instead of testing for interop subscribers/subscriptions in operator implementations, this refactor moves the test into
subscribeToObservable
- which is where the interop subscription takes place - and ensures that function behaves likesubscribe
calls made to this package's observables.That is, it ensures that the subscriber that's passed in is what's returned. If the subscription that's received is not the subscriber, said subscription is added to the subscriber so that unsubscription chains correctly.
The code is much simpler and all of the tests that were added in #5059 pass.
I've made some changes to this PR, as it can be used to resolve the problem that #5239 and #5243 sought to address.
It's explained in this comment:
rxjs/src/internal/util/subscribeWith.ts
Lines 5 to 37 in ba08e58
Essentially, the
subscribeWith
util can be used to ensure that subscription chains are not broken - by interop observalbes - insubscribeToObservable
or in any operator'scall
method.This PR does not make any changes to operator
call
implementations. I'll do that in a separate PR, if this PR passes review.If you look at the change made in #5239, it should be clear that the implementation of
subscribeWith
will solve the problem in a similar manner to the change that's in that PR:rxjs/src/internal/operators/finalize.ts
Lines 75 to 80 in b92d1db
Related issue: #5051