Skip to content

Instantly share code, notes, and snippets.

@arnaudgiuliani
Created March 2, 2018 17:41
Show Gist options
  • Select an option

  • Save arnaudgiuliani/7cc1d862cefa6fbe2e4a96d66904e2c0 to your computer and use it in GitHub Desktop.

Select an option

Save arnaudgiuliani/7cc1d862cefa6fbe2e4a96d66904e2c0 to your computer and use it in GitHub Desktop.
Koin 0.9.0 - Dynamic parameter with ViewModel
class DetailActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
//...
val detailViewModel = getViewModel<DetailViewModel>(parameters = mapOf("id" to id))
detailViewModel.getDetail()
}
}
class DetailViewModel(val id : String) : ViewModel() {
fun getDetail() {
// Get details with injected "id" param
}
}
val weatherModule = applicationContext {
// ViewModel for Detail View
viewModel { params -> DetailViewModel(params["id"]) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment