When I develop ViewModel in compose desktop, I hav...
# multiplatform
v
When I develop ViewModel in compose desktop, I have a question. Until now, I use remember + DisposableEffect to create ViewModel. But, Now that I think about the produceState can be the same effect. • remember + DisposableEffect case
Copy code
fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        val viewModel = remember {
            AppViewModel()
        }
        App(viewModel = viewModel)

        DisposableEffect(Unit) {
            onDispose {
                viewModel.destroy()
            }
        }
    }
}
• produceState case
Copy code
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)