Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sealed class MyViewState {
class Error(val cause: String): MyViewState()
object Loading: MyViewState()
class DataLoaded(data: Data): MyViewState()
}
[...MyView...]
fun render(viewState: MyViewState) {
when (viewState) {
MyViewState.Error -> { // handle error state
}
MyViewState.Success -> { // populate view accordling or change it
}
MyViewState.Loading -> { // show a loading somehow
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.