Created
July 2, 2018 22:41
-
-
Save featzima/bf00d66ddf1f7d1befc6065381891a96 to your computer and use it in GitHub Desktop.
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
data class MyViewModel( | |
private val myEndpoint: MyEndpoint): DisposableViewModel() { | |
private val searchText = ChannelLiveData("") | |
private val inProgress = ChannelLiveData(false) | |
private val result = ChannelLiveData("") | |
init { | |
disposableLaunch { | |
searchText | |
.openSubscription() | |
.consumeEach { searchText -> | |
inProgress.send(true) | |
val searchResult = myEndpoint.search(searchText) | |
inProgress.send(false) | |
result.send(searchResult) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment