Skip to content

Instantly share code, notes, and snippets.

@gpeal
Last active August 23, 2018 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpeal/1ec04f9bce2bb1f80605a9f350daf203 to your computer and use it in GitHub Desktop.
Save gpeal/1ec04f9bce2bb1f80605a9f350daf203 to your computer and use it in GitHub Desktop.
MvRx
data class HelloWorldState(val title: String = "Hello World") : MvRxState
class HelloWorldViewModel(initialState: HelloWorldState) : MvRxViewModel<HelloWorldState>(initialState) {
fun getMoreExcited() = setState { copy(title = "$title!") }
}
class HelloWorldFragment : BaseFragment() {
private val viewModel by fragmentViewModel(HelloWorldViewModel::class)
override fun EpoxyController.buildModels() = withState(viewModel) { state ->
header {
title(state.title)
}
basicRow {
onClick { viewModel.getMoreExcited() }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment