Skip to content

Instantly share code, notes, and snippets.

@SeongUgJung
Last active August 6, 2019 16:41
Show Gist options
  • Save SeongUgJung/dc6050875a904015843df2e3dbc6cf79 to your computer and use it in GitHub Desktop.
Save SeongUgJung/dc6050875a904015843df2e3dbc6cf79 to your computer and use it in GitHub Desktop.
typealias DisposableFunction = () -> Disposable // e.g) Observable.just().subscrbie()
class RxLifecycle : LifecycleObserver {
private var onInit: DisposableFunction? = null
private var initDisposable: Disposable? = null
override fun onInit() {
// create 시점에 Stream 실행
initDisposable = this.onInit?.invoke()
}
override fun onDeinit() {
// destroy 시 실행된 stream 종료
if (initDisposable?.isDisposed == false) {
initDisposable?.dispose()
}
}
fun onVisible()
fun onInvisible()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment