Created
March 2, 2018 17:41
-
-
Save arnaudgiuliani/7cc1d862cefa6fbe2e4a96d66904e2c0 to your computer and use it in GitHub Desktop.
Koin 0.9.0 - Dynamic parameter with ViewModel
This file contains hidden or 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
| class DetailActivity : AppCompatActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| //... | |
| val detailViewModel = getViewModel<DetailViewModel>(parameters = mapOf("id" to id)) | |
| detailViewModel.getDetail() | |
| } | |
| } |
This file contains hidden or 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
| class DetailViewModel(val id : String) : ViewModel() { | |
| fun getDetail() { | |
| // Get details with injected "id" param | |
| } | |
| } |
This file contains hidden or 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
| 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