-
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
Observable.subscribe checks 'instanceof' Subscription instead of shape #748
Comments
I would rather first question your overall approach. Subclassing Subject is not meant to be a common necessity. In fact, I have never encountered such case where I had to subclass Subject.
Seems fishy. Why can't you merge all the Observables to be observed by the Subject, and then subscribe to that merged result using the Subject as observer? Merge gives you this functionality of defer calling complete until the last observable completes: var e1 = hot('--a-----b-----c----|');
var e2 = hot('-----d-----e-----f---|');
var result = e1.merge(e2, rxTestScheduler);
var expected = '--a--d--b--e--c--f---|'; In other words, what are you trying to achieve? We might be able to find a different solution to your problem. |
Sure. This was more of a thought exercise for me to understand Subjects, but I want to simulate a multiplexed Websocket. That is, I want to create a class that exposes a shared observable. The items in the output sequence will all conform to a type T which has a Someone pointed me to your https://github.com/cyclejs/rx-injectable-observable, which may be exactly what I want and should use, but I wanted to build something rudimentary with Subjects on my own for simple learning purposes (I'm quite new to RxJS). :) The fact that I could't get my |
Honestly, as a first attempt, the best way to create a custom subject right now is to use Otherwise feel free to try to extend Subject, but know that playing with things like On the |
Subscribing to an Observable with a Subject should be fine, seems covered. This issue is about subclasses of Subject. |
Thanks all for getting back. I recognize that overriding subjects is not the best approach in most cases and I'm not using it anymore myself so this issue doesn't actually affect me, but couldn't the
Anywhere in the code that tests for |
@ntilwalli indeed, that makes sense. I wonder if there is any reason to wrap a Subject in a Subscriber. I'm curious to see what performance boost would your suggestion bring. |
I think that I've fixed this with #724, but inadvertently (I wasn't trying to fix it, I was fixing something else), and in a way that's probably less desirable than @ntilwalli's proposal. |
This issue is actually not fixed. I've created a PR integrating my suggestion. #863 |
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. |
Currently
Subject
extendsObservable
and only implementsSubscription
so it doesn't see theSubscription
function on it's inheritance chain. This is an issue because currently thesubscribe
method onObservable
checks whether thesubscriber
is aninstanceof Subscription
. If thesubscriber
is aSubject
it returnsfalse
and then wrapssubscriber
in aSubscriber
and proceeds.This seems faulty because this behavior will hide any attempt to override any of the
Subscriber
methods in theSubject
.I was trying to create a custom
Subject
that reference counts the number of Observables it is subscribed to so it can defer callingcomplete
until the last observable completes but this became an issue. I don't know if this is a bug, but it seems like non-ideal behavior. Would it be possible to addSubscriber
to the prototypal chain ofSubject
, or, inObservable.subscribe
change theinstanceof
call to instead check the shape of the passed insubscriber
?The text was updated successfully, but these errors were encountered: