Skip to content

Instantly share code, notes, and snippets.

@bernaferrari
Last active August 13, 2019 21:54
Show Gist options
  • Save bernaferrari/db0676529c1b8924dcd61775ab885692 to your computer and use it in GitHub Desktop.
Save bernaferrari/db0676529c1b8924dcd61775ab885692 to your computer and use it in GitHub Desktop.
Simple mvrx sample
data class HelloWorldState(val title: String = "Hello World") : MvRxState
class HelloWorldViewModel(initialState: HelloWorldState) : MyBaseMvRxViewModel<HelloWorldState>(initialState, debugMode = BuildConfig.DEBUG) {
fun getMoreExcited() = setState { copy(title = "$title!") }
}
class HelloWorldFragment : BaseFragment() {
private val viewModel: HelloWorldViewModel by fragmentViewModel()
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