Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Latest commit

 

History

History

androidx-viewmodel

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

AndroidX ViewModel extensions for Katana

The extensions declared in this artifact simplify ViewModel injection with Katana. Also see katana-androidx-viewmodel-savedstate.

Create a ViewModel binding inside a module:

data class MyViewModel(val someDependency: SomeDependency) : ViewModel()

Module {
    
    viewModel { MyViewModel(get()) }
}

Inject ViewModel in your Activity or Fragment:

class MyFragment : Fragment(),
                   KatanaTrait {
                   
    override val component = Component(...)
    
    private val viewModel by viewModel<MyViewModel, MyFragment>() 
}