Skip to content

Instantly share code, notes, and snippets.

@oradkovsky
Created April 28, 2020 19:07
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 oradkovsky/96d323f109ef1c06cbe248ec182931fc to your computer and use it in GitHub Desktop.
Save oradkovsky/96d323f109ef1c06cbe248ec182931fc to your computer and use it in GitHub Desktop.
// declare view model
class MyViewModelWithState(
private val handle: SavedStateHandle, //always first param btw
private val gson: Gson
) : ViewModel() {
// make use of state bundle as usual
}
// modify corresponding module
val viewModelsModule = module {
viewModel { (handle: SavedStateHandle) -> MyViewModelWithState(handle, get()) }
}
// make use of
class MyFragmentWithState : Fragment() {
private val myViewModelWithState: MyViewModelWithState by stateViewModel()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment