Skip to content

Instantly share code, notes, and snippets.

@lucanicoletti
Created May 28, 2019 14:55
Show Gist options
  • Save lucanicoletti/f3d318169ed0384d01378ce4b9de4e43 to your computer and use it in GitHub Desktop.
Save lucanicoletti/f3d318169ed0384d01378ce4b9de4e43 to your computer and use it in GitHub Desktop.
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