-
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
Removal of unsanctioned introduction of context #3230
Conversation
Observing functions (callbacks) are given to `.subscribe(next, error, complete)` by an outside code. But `rxjs` dictates a context of execution, instead of leaving it `undefined`. It sort of disrespects separation between callbacks that come from outside, and its own internals on the public API of the library. As a result, there are issues ReactiveX#3229, ReactiveX#1981, ReactiveX#1949, ReactiveX#2140, that happen due to `rxjs` mangling with execution context. Library behaves in an unexpected way. This change fixes an unsanctioned introduction of context to callback. Now, it is possible, that this weird behaviour was introduced to help some other parts of the lib. Tests should show this. And may be those places should change instead of keeping users of the library puzzled.
Generated by 🚫 dangerJS |
Can you please add a test that would fail should this change? |
@benlesh I don't think that a test for this tiny beautification of code failure is needed. I bet, that no-one would need to change this anyway. And if someone does, she will have reasons stronger than mere human error comprehension concern. |
The point was to add a test that is broken before the fix, so we can see that the fix works. I can't merge this without a test. |
@benlesh okey, then I need your help here.
|
Really the test should come first. Basically any code that is broken before the change, and some assertions around it. Just keep in mind that it can't run for a long time, because it'll slow down all of our builds. |
Since commenting on the linked issue, I've seen this tweet from @trxcllnt:
The tweet suggests that using the subscriber as the context was a design decision and that it should not be replaced with Note that this PR does not fix an error. Rather, its change effects a obs$.subscribe(
observer.next,
observer.error,
observer.complete
); Interestingly, |
@cartant Wow!
If current design stays, do
|
@cartant can you point to a code that illuminates quoted part from tweet:
My callback should be responsible to call |
Yup. There's the breaking change. Although, IMO, Current behavior is also leaking implementation. There are other proposals to fix this. A start event, and one that passes the subscription to the next handler as the second argument. This all requires more thought. But I'd like to eliminate the implementation leaks. |
@cartant aye, good eye. The goal of context-rebinding in Combining Observer and Disposable into a single class was indeed to cut down on intermediate disposables, as well as optimizing the Observer chain by storing references to sink Observers as instance properties rather than closure state. The decision to use the To be clear, the challenge here was to ensure Observers could unsubscribe from potentially infinite synchronous sources (again, in the absence of something like cancelation tokens, Observable.range(0, Infinity).subscribe((function(x) {
if (x > 100) { this.unsubscribe(); }
})); A better way to do the above is to use I know we do have this test that validates the context rebinding happens correctly on duck-typed anonymous Observer objects, but I can't seem to find any that validate the context is maintained for PartialObservers. Also I seem to remember a conversation with @jayphelps a while back about |
Also to note, we bend over backwards to ensure the |
Looks like a rabbit hole goes deep.
|
Seems like we've worked this out, I'm going to close it. |
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. |
Description:
Observing functions (callbacks) are given to
.subscribe(next, error, complete)
by an outside code. Butrxjs
dictates a context of execution, instead of leaving itundefined
. It sort of disrespects separation between callbacks that come from outside, and its own internals on the public API of the library.As a result, there are issues #3229, #1981, #1949, #2140, that happen due to
rxjs
mangling with execution context of externally given callbacks. Library behaves in an unexpected way.This change fixes an unsanctioned introduction of context to callback.
Now, it is possible, that this weird behaviour was introduced to help some other parts of the lib. Tests should show this. And may be those places should change instead of keeping users of the library puzzled (number of issues times minimum 1-2 hours, plus unreported cases).
Related issue (if exists): #3229, #1981, #1949, #2140
If this will be a no-fix, at least put comment near the place that is pointed in a stack overflow error, which people get. Put some indications for poor devs 😢