Skip to content
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

RxView.bindView(View view, Observable<T> source) #70

Closed
passsy opened this issue Aug 6, 2015 · 7 comments
Closed

RxView.bindView(View view, Observable<T> source) #70

passsy opened this issue Aug 6, 2015 · 7 comments

Comments

@passsy
Copy link

passsy commented Aug 6, 2015

When I updated to RxAndroid 1.0.0 I missed ViewObservable.bindView(View view, Observable<T> source). Will it be added here? Is there another way I'm not seeing to replace this API?

https://github.com/ReactiveX/RxAndroid/blob/4bff437edfa24dde62c90d44b019b9a35855db6a/rxandroid/src/main/java/rx/android/view/ViewObservable.java

I often used a combination of this to attach observables to items in my adapters.

ViewObservable.bindView(myView, Observable.interval(500, TimeUnit.MILLISECONDS))
        .subscribe(/* do something with myView */);

Manually unsubscribing looks like unnecessary extra effort.

@JakeWharton
Copy link
Owner

This library is for property and event binding only. That method was an analogous to the poorly-named bindActivity or bindFragment but for views which relate to the lifecycle of these objects and thus firmly outside the scope of this library.

Once view attach/detach events are added you'll be able to use this library to compose operators to a functionally-equivalent solution along the lines of:

Observable.interval(500, MILLISECONDS)
    .takeUntil(RxView.attachEvents(myView).filter(e -> e.kind() == DETACH))
    .subscribe(/* do something with myView */);

This can easily be abstracted into a static helper method of the same signature as the ViewObservable.bindView method.

@passsy
Copy link
Author

passsy commented Aug 6, 2015

I really like the view attach/detach event solution! Are these events planned for the near future?

@JakeWharton
Copy link
Owner

Yep. They're on my list (which I should probably move to GitHub issues).

@ZacSweers
Copy link
Contributor

Talked with @dlew and he agreed it fits within the scope of RxLifecycle, pull request here: trello-archive/RxLifecycle#12

@ZacSweers
Copy link
Contributor

On a related note, some of the event names/usage overlap (like attach/detach). @JakeWharton @dlew any interest in maybe consolidating these in some way so users don't end up with duplicates?

@JakeWharton
Copy link
Owner

Even better!

On Thu, Aug 6, 2015 at 8:50 PM Henri (Zac) Sweers notifications@github.com
wrote:

On a related note, some of the event names/usage overlap (like
attach/detach). @JakeWharton https://github.com/JakeWharton @dlew
https://github.com/dlew any interest in maybe consolidating these in
some way so users don't end up with duplicates?


Reply to this email directly or view it on GitHub
#70 (comment)
.

ZacSweers added a commit to ZacSweers/RxBinding that referenced this issue Aug 9, 2015
JakeWharton pushed a commit that referenced this issue Aug 9, 2015
@passsy
Copy link
Author

passsy commented Aug 12, 2015

API in 1.0.1-SNAPSHOT:

Observable.interval(500, MILLISECONDS)
    .takeUntil(RxView.detaches(myView))
    .subscribe(/* do something with myView */);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants