-
Notifications
You must be signed in to change notification settings - Fork 223
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
Expose observable source for ObservableSubscribeProxy #95
Comments
In the face of it, I don't think so. It has an intern observable but disposal of intermediary streams is not something we want to encourage. Disposal only travels up, so everything below it would be unbound (this caused a lot of issues when using something via compose()). What would the API look like? |
I get your consideration.
I expect the API of public interface ObservableSubscribeProxy<T> {
...
Observable<? extends T> getSource();
} then I can do fun <T : Any> ObservableSubscribeProxy<T>.mySubscribe(f: () -> Unit): Disposable {
return getSource().doOnSubscribe { f() }
.subscribe(Consumer {}, Consumer {})
} Any alternative solutions? Cheers. |
hmm. I see the value from a flexibility, but your example actually ends up not using AutoDispose's functionality. Under the hood, this works because we decorate the received observer or lambda observers with a custom autodisposing one. In your example, you're just hitting RxJava's standard You could adjust it to use an autodispose one, but now you no longer have access to the scope, so we'd need to then provide that somewhere too, so now we're talking about two extra methods ( Two ideas that come to mind:
interface ObservableSubscribeProxy<T> {
// Currently existing methods...
// New method
ObservableExtensionsHook<T> extensions()
}
interface ObservableExtensionsHook<T> {
Observable<T> source()
Maybe<?> scope()
}
// Your example
fun <T : Any> ObservableExtensionsHook<T>.mySubscribe(f: () -> Unit): Disposable {
return source().doOnSubscribe { f() }
.autoDisposeWith(scope())
.subscribe(Consumer {}, Consumer {})
}
// In use
Observable.just(1)
.autoDisposeWith(this)
.extensions()
.mySubscribe(...) Basically, I like this, but |
I manage to solve my question. interface MyProxy<T> {
fun sourceObservable(): Observable<T>
fun lifecycleOwner(): LifecycleOwner
}
class MyProxyImpl<T>(val source: Observable<T>, val lifecycleOwner: LifecycleOwner): MyProxy<T> {
override fun sourceObservable(): Observable<T> = source
override fun lifecycleOwner(): LifecycleOwner = lifecycleOwner
}
fun <T> Observable<T>.autoDispose(lifecycleOwner: LifecycleOwner): MyProxy<T> {
return MyProxyImpl(this, lifecycleOwner)
}
fun <T : Any> MyProxy<T>.mySubscribe(f: () -> Unit): Disposable {
return sourceObservable().doOnSubscribe { f() }
.autoDisposeWith(lifecycleOwner())
.subscribe(Consumer {}, Consumer {})
} |
With
.to(ObservableScoper(AndroidLifecycleScopeProvider.from(this)))
, we can't take advantage of kotlin's extension to use my custommySubscribe
method since it is aObservableSubscribeProxy
type.Do you think it is better to expose the observable source for
ObservableSubscribeProxy
?The text was updated successfully, but these errors were encountered: