vnycall74
05/04/2023, 6:07 PMfun main() = application {
Window(onCloseRequest = ::exitApplication) {
val viewModel = remember {
AppViewModel()
}
App(viewModel = viewModel)
DisposableEffect(Unit) {
onDispose {
viewModel.destroy()
}
}
}
}
• produceState case
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
val viewModel by produceState(AppViewModel()) {
awaitDispose {
value.destroy()
}
}
App(viewModel = viewModel)
}
}
So, what I'm curious about is, is the same result obtained in both cases. And is produceState
safe?
I think the state never changes before using the set value, but I'm worried that the view model will change caused to other reasons. (something other side effects that I don't know)