Skip to content

Instantly share code, notes, and snippets.

@HaHaBird
Created July 14, 2021 07:28
Show Gist options
  • Save HaHaBird/38fdbd9a18f0b102ec4458cb77ac5def to your computer and use it in GitHub Desktop.
Save HaHaBird/38fdbd9a18f0b102ec4458cb77ac5def to your computer and use it in GitHub Desktop.
fun <T> Observable<T>.autoDispose(provider: ScopeProvider): ObservableSubscribeProxy<T> =
this.`as`(AutoDispose.autoDisposable(provider))
fun <T> Observable<T>.autoDispose(owner: LifecycleOwner, untilEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY): ObservableSubscribeProxy<T> =
this.`as`(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(owner, untilEvent)))
fun <T> Flowable<T>.autoDispose(provider: ScopeProvider): FlowableSubscribeProxy<T> =
this.`as`(AutoDispose.autoDisposable(provider))
fun <T> Flowable<T>.autoDispose(owner: LifecycleOwner, untilEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY): FlowableSubscribeProxy<T> =
this.`as`(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(owner, untilEvent)))
@HaHaBird
Copy link
Author

需要依赖:
api 'com.uber.autodispose:autodispose:1.4.0'
api 'com.uber.autodispose:autodispose-android-archcomponents:1.4.0'
api 'com.uber.autodispose:autodispose-android-archcomponents-ktx:1.2.0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment