-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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 creation from Subscriber[T]=>Unit for Scala #923
Observable creation from Subscriber[T]=>Unit for Scala #923
Conversation
RxJava-pull-requests #863 SUCCESS |
RxJava-pull-requests #864 SUCCESS |
Good to hear :-) |
Is this intended as fixes for the 0.17.0 Release Candidate or for 0.17.1? |
Looking at this, made me wonder why we deprecate
|
What use case are you referring to? |
Like this:
|
It would just be like this where the def mouseDrag: Observable[MouseEvent] = Observable.create(subscriber => {
val handler = EventHandler[MouseEvent](m => {
subscriber.onNext(m)
})
target.addEventHandler(MouseEvent.MOUSE_DRAGGED, handler)
subscriber.add( {
target.removeEventHandler(MouseEvent.MOUSE_DRAGGED, handler)
})
}) If we do decide we want an overload, it won't be the |
That looks so imperative to me ... |
Don't fully understand your comment about the overloads, Java can handle overloading both
|
Not sure why being "imperative" is such a big deal here: subscriber.add( {
target.removeEventHandler(MouseEvent.MOUSE_DRAGGED, handler)
}) versus
... but I can understand a preference one direction versus the other. Updated ... By the way we have lots of operators where it is "imperative" on the inside while "functional" on the outside. That's part of the nature of RxJava residing on an imperative platform, so I don't see this as being an issue. |
This is the current signature: public final static <T> Observable<T> create(OnSubscribe<T> f) And public static interface OnSubscribe<T> extends Action1<Subscriber<? super T>> |
Thus, with overloads you'd end up with two things looking exactly the same: public final static <T> Observable<T> create(OnSubscribe<T> f)
public final static <T> Observable<T> create(OnOtherSubscribe<T> f) Their types would be: public static interface OnSubscribe<T> extends Action1<Subscriber<? super T>>
public static interface OnOtherSubscribe<T> extends Func1<Observer<? super T>, Subscription> |
Isn't
Looks fine with me (and it avoid breaking all existing explanations/articles about Rx that use the legacy signature ...) |
Yes, and we're killing it because the name is wrong (and we intended on having only a single |
???? "We're not going to have two methods with different signatures with basically the same name." Isn't that the very definition of overloading? |
Not when they are exactly the same :-) Put these two next to each other, without reading the docs which one should I use? public final static <T> Observable<T> create(OnSubscribe<T> f)
public final static <T> Observable<T> create(OnSubscribeFunc<T> f) |
That does not bother me, just as Of course, it would be simpler if the aliases
|
The Having both an The reason the As for the aliases, they are done because of the complexity of co/contr-variant generics that people must deal with every time they use If we were to give up on ease of use for that problem and on the challenges of dynamic languages disambiguating between the overloads then yes, the public final static <T> Observable<T> create(Action1<Subscriber<? super T>> f) {
return new Observable<T>(f);
}
public final static <T> Observable<T> create(final Func1<Observer<? super T>, Subscription> f) {
return new Observable<T>(new Action1<Subscriber<? super T>>() {
@Override
public void call(Subscriber<? super T> subscriber) {
Subscription s = f.call(subscriber);
if (s != null && s != subscriber) {
subscriber.add(s);
}
}
});
} |
Another consideration ... my understanding of the event listeners on For example, take a look at this code: https://github.com/Netflix/RxJava/blob/master/rxjava-contrib/rxjava-android/src/main/java/rx/operators/OperatorObserveFromAndroidComponent.java#L68 Line 99 uses Returning that Also, common event listeners end up with cover libraries such as Therefore, I don't think the need of an overload is worth confusing the API by having two different ways of doing things with nuanced differences between them (how they behave with synchronous sources). For example, in the version with |
I'd say 0.17.0, the earlier people can use it, the better ;-) |
Observable creation from Subscriber[T]=>Unit for Scala
This PR adds the
Subscriber
type, andObservable.apply[T](Subscriber[T] => Unit)
.Additionally, I made some tweaks in
RxScalaDemo
, and I could remove all comments of the kindTODO something behaves weirdly here
, because now the weird behavior was gone. Seems like there was some progress in RxJava core :-)Sorry that this PR mixes several topics, let me know if you want me to split it by topic.
/cc @headinthebox @vjovanov