Created
January 28, 2018 07:41
-
-
Save VladimirMi/2d2416a952397edf14f9f2c978198351 to your computer and use it in GitHub Desktop.
Kotlin bind view reactive
This file contains 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
fun <T> bind(lifecycle: Observable<Lifecycle>, | |
mainThreadScheduler: Scheduler, | |
state: Observable<T>, | |
viewAction: (T) -> Unit) { | |
lifecycle | |
.filter { CREATE } | |
.switchMap { state } | |
.observeOn(mainThreadScheduler) | |
.takeUntil(lifecycle.filter { DESTROY }) | |
.subscribe(viewAction) | |
} | |
fun bindData(lifecycle: Observable<Lifecycle>) { | |
fun <T> bindSimple(state: Observable<T>, viewAction: (T) -> Unit) = | |
bind(lifecycle, AndroidSchedulers.mainThread(), state, viewAction) | |
bindSimple(Observable.just(1), ::action) | |
} | |
fun action(int: Int) { | |
// do smth | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment