Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Let manageSubscription(Subscription) return Subscription #59

Closed
passsy opened this issue Jan 9, 2017 · 4 comments · Fixed by #73
Closed

Let manageSubscription(Subscription) return Subscription #59

passsy opened this issue Jan 9, 2017 · 4 comments · Fixed by #73
Labels

Comments

@passsy
Copy link
Contributor

passsy commented Jan 9, 2017

RxTiPresenterSubscriptionHandler.manageSubscription(Subscription...) returns void. It would be cool if there is a manageSubscription function with the following signature:

public Subscription manageViewSubscription(@NonNull final Subscription subscription)

Usage

// inside TiPresenter

val rxHelper: RxTiPresenterSubscriptionHandler(this)
val sub: Subscription? = null

/**
 * download some data
 */
fun download() {
    // subscription is managed, it will be cancelled when the Presenter gets destroyed
    sub = rxHelper.manageSubscription(myService.downloadSomething().subscribe{ data -> 
        sendToView { view -> view.showData(data) }
    })
}

/**
 * cancel download before it completes
 */
fun cancelDownload() {
    sub?.unsubscribe()
}
@passsy passsy added the rx label Jan 9, 2017
@StefMa
Copy link
Contributor

StefMa commented Jan 9, 2017 via email

@passsy
Copy link
Contributor Author

passsy commented Jan 10, 2017

right now:

mSub = someObservable.subscribe();
rxHelper.manageSubscription(mSub);

proposed:

mSub = rxHelper.manageSubscription(someObservable.subscribe()) 

it saves one line of code 😄

@StefMa
Copy link
Contributor

StefMa commented Jan 25, 2017

Does it any sense, with the current implementation?
I guess not.
We can only return an array of Subscription[]s and then you have to extract it, after you put it into the managerSubscriptions.

@passsy
Copy link
Contributor Author

passsy commented Jan 25, 2017

of course we have to change the interface and add a new method. We can still change the public API because manageSubscription with varargs is only released in rc builds.

// for single subscriptions
public Subscription manageSubscription(Subscription sub);

// for multiple
public void manageSubscriptions(Subscription... subs);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

2 participants