-
Notifications
You must be signed in to change notification settings - Fork 3k
Add AndroidObservable#bindView() #53
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
Conversation
@@ -119,6 +121,30 @@ private AndroidObservable() { | |||
} | |||
|
|||
/** | |||
* Binds the given source sequence to the view. | |||
* <p /> | |||
* <p/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-closing paragraph tags are not valid in Javadoc's (awful) HTML. Each of these should just be a single <p>
declaration on its own line between paragraphs.
Thanks for the review folks, could you take another look? Apparently files like AndroidObservable.java contains some non-conventional code. |
@JakeWharton do you think it would make sense to add a checkstyle step to the build? So people can run against it before pushing. I don't feel strong about any particular code style as long as everyone follows it. |
* | ||
* @see rx.android.observables.AndroidObservable | ||
*/ | ||
public class OperatorViewAttachStateBinding<T> implements Observable.Operator<T, T>, View.OnAttachStateChangeListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View.OnAttachStateChangeListener
here is an implementation detail. I would move it out the way OperatorTextViewInput
does it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the name of the class does not reflect what it really does. It seems like it's more of a OperatorUnsubscribeOnViewDetached
-- naming is the hardest thing in the world.
@hamidp Could you take another look? I think the last commit addresses your points. |
@omo Thanks! I looked at some other code, and it seems like something like this might work
I have no strong feelings on it though. Last thought if we go with your implementation is to rename the class (again sorry) to |
@hamidp Tried the snippet and found that it is actually better. It is more polite, as it sends onComplete() instead of silently unsubscribing it. Thanks for the suggestion! Pushed another commit. I'd keep takeUntilViewDetached private and left the bindView() name because
Once we resolve #12 and let other bindXx() behave more like takeUntil(), we could decouple the main thread binding from the stream closing behavior and make takeUntilXx() family public. |
@omo Any reason to keep |
@hamidp It's simply well factored IMHO. |
@omo I can see that -- definitely makes the bindView method shorter and easier to read. My objection to the helper method being there at all is that |
That's fair. Probably having a separate class is the "right" way but obviously overkill. Let me just inline it. |
*/ | ||
public static <T> Observable<T> bindView(final View view, Observable<T> source) { | ||
Assertions.assertUiThread(); | ||
return source.observeOn(mainThread()).takeUntil(Observable.create(new Observable.OnSubscribe<Object>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general, observeOn
should appear "on the right" in a sequence of steps, subscribeOn
on "the left".
it wouldn't change semantics here, but I think it's better style to invoke observeOn
last.
bindView() is a sister of bindActivity() and bindFragment(). Thanks for View.OnAttachStateChangeListener, it doesn't require any manual unsubscription. It frees developers from overriding View#onDetachFromWindow().
@mttkay Thanks for the review! And you're right. Unsubcription handling is nice to have and Note that I did rebase and squash for clarity. |
👍 if someone else can thumb this, we can get it in. |
👍 from me as well.
|
Add AndroidObservable#bindView()
should be done as a follow up, as there was an occurrence of this in this PR as well |
Thank you! I'm preparing the followup. |
bindView() is a sister of bindActivity() and bindFragment().
Thanks for View.OnAttachStateChangeListener, it doesn't require
any manual unsubscription. It frees developers from overriding
View#onDetachFromWindow().