Created
December 24, 2017 08:49
-
-
Save kubode/0896e6429c360160cd2e642b66ba722a to your computer and use it in GitHub Desktop.
Lifecycleを使ってAutoDisposableを実現する ref: https://qiita.com/kubode/items/9d7f212219652e8439a9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val LifecycleOwner.disposeOn: Disposable.(Lifecycle.Event) -> Unit | |
get() = { disposeEvent -> disposeOn(lifecycle, disposeEvent) } | |
val LifecycleOwner.autoDispose: Disposable.() -> Unit | |
get() = { autoDispose(lifecycle) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooFragment: Fragment() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
lifecycle.asObservable() | |
.filter { it == Lifecycle.Event.ON_RESUME } | |
.subscribe { toast("resumed") } | |
.autoDispose() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment