-
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
Why do Subject operators work this way? #2487
Comments
Interesting, I never noticed that. For what it is worth in the original .NET CLR Observables, and continuing through the most recent version, Subjects behave as you seem to expect. i.e. var subject = new BehaviorSubject<int>(1); // BehaviorSubject<Int32>
var projected = from n in subject select n * 2; // IObserable<Int32> Now this may be simply due to the practical (lines of code) limitation based on the nature of extension methods in C#/VB/CLR (in other words there are no HKTs), and thusly not as revealing of intent, but I doubt it. Looking at RxScala it returns |
Though it is not identical, I'd consider this as similar to #2391 . Best recommended way is to refer type definition to see if it's expected or not. Note I'm not saying you should use TypeScript and it can be bit annoying to refer type definition - it's just way to confirm it with status quo of implementation. Aside of those, for this specific matter it is interesting perspective how we'd like to deal with inherited variant of Observables. For example, if you have custom extended Observable (like |
I guess the same situation is when the This allows me to call methods directly on the observer and do very weird things such as the following:
This prints to console:
Actually, I've seen this on StackOverflow where the poster was asking why his Observable chain doesn't work. Until then it never occurred to me that this is even possible :). Update: mentioned also in #2314 |
That's definitely a little scary that something as basic as |
I would like to add here that i've seen people rely on this behavior on Ps. My first reaction here was... Yikes! |
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. |
I'm asking for the reasoning rather than a technical explanation. I understand that subject operators return an AnonymousSubject which passes events to the source. This seems very confusing, as I'd expect the derived values to be one of two things:
It is also very similar to the common mistake with mutable data structures:
I don't see a good reason for introducing such behavior, but I'm pretty sure it has been discussed before. Sorry for raising this question again, but I couldn't find any public explanation. I believe it belongs in the manual, because the first time I encountered this felt like triggering a mutability booby trap.
The text was updated successfully, but these errors were encountered: