VMInject
Annotates the constructor of a ViewModel which will be injected via Tangle.
These ViewModels are scoped to the TangleViewModelMapSubcomponent, which can be accessed via the tangleViewModel delegate function.
Since
0.10.0
Samples
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import tangle.inject.TangleParam
import tangle.inject.test.utils.MyRepository
import tangle.inject.test.utils.Sample
import tangle.viewmodel.VMInject
import tangle.viewmodel.fragment.tangleViewModel
fun main() {
//sampleStart
class MyViewModel @VMInject constructor(
val repository: MyRepository,
@TangleParam("userId")
val userId: Int
) : ViewModel()
class MyFragment : Fragment() {
val viewModel by tangleViewModel<MyViewModel>()
}
//sampleEnd
}