mbonnin
03/15/2023, 12:08 PMViewModel
as a default argument in Composable
a bunch of times. Last example in NIA:
internal fun BookmarksRoute(
onTopicClick: (String) -> Unit,
modifier: Modifier = Modifier,
// No one ever passes a different value here
viewModel: BookmarksViewModel = hiltViewModel(),
) {
Is there a specific reason for this? I've see this message but it's 2 years old and it mentions DI but I don't really see myself faking the ViewModel in tests (it's a final class). Or should I? Is there still a reason to use this pattern?efemoney
03/15/2023, 12:14 PM// This composable is just DI glue
@Composable fun DiscoverUi(vm: VM = hiltVModel) {
DiscoverUi(vm.state)
}
// This is the composable you test & preview
@Composable fun DiscoverUi(state: DiscoverState, modifier: M = Modifier) {
Box|Column|Scaffold etc
}
mbonnin
03/15/2023, 12:15 PM@Composable fun DiscoverUi(vm: VM = hiltVModel) {
DiscoverUi(vm.state)
}
and not
@Composable fun DiscoverUi() {
val vm: VM = hiltVModel(...)
DiscoverUi(vm.state)
}
?DiscoverUi()
with a different viewModel?efemoney
03/15/2023, 12:21 PMmbonnin
03/15/2023, 12:22 PMcurioustechizen
03/15/2023, 12:29 PMmbonnin
03/15/2023, 12:32 PMAlbert Chang
03/15/2023, 2:01 PMKevin Worth
03/16/2023, 9:03 PMAlbert Chang
03/17/2023, 4:37 PMKevin Worth
03/17/2023, 7:11 PMAlbert Chang
03/18/2023, 4:50 PM