vnycall74
01/05/2023, 6:10 AMview model
for Kotlin Multiplatform(Desktop, Android
) projects?
In Android, the view model extends ViewModel (Android), but that's a natural thing to say, Desktop hasn't ViewModel. So I can't use the common view model.
Additionally, I think some things, but It looks not good...
A. Inject view model of each platform
Window(onCloseRequest = { // Do something }, title = "Test") {
val testViewModel by inject<TestViewModel>(TestViewModel::class.java)
TesetScreen(
user = testViewModel.user,
testState = testViewModel.testState.collecAsState().value,
testAction = testViewModel::testAction
)
DisposableEffect(Unit) {
onDispose {
testViewModel.onCleared()
}
}
}
B. Use use-case direct in the Composable Screen
Window(onCloseRequest = { // Do something }, title = "Test") {
val getUserUseCase by inject<GetUserUseCase>(GetUserUseCase::class.java)
val getTestState by inject<GetUserUseCase>(GetUserUseCase::class.java)
TesetScreen(
user = testViewModel.user,
testState = getTestState().collecAsState().value,
testAction = { doSomething() }
)
}
C. Don't use the view model...
What do you think about the above logic and how do you design architecture KMP?Mustafa Ozhan
01/05/2023, 7:26 AMvnycall74
01/05/2023, 8:51 AM