Created
May 28, 2019 14:55
-
-
Save lucanicoletti/f3d318169ed0384d01378ce4b9de4e43 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
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