Does `LaunchedEffect` have any meaning on Desktop?...
# compose-desktop
v
Does
LaunchedEffect
have any meaning on Desktop? Since there's no android lifecycle here?
j
Of course. It launches a coroutine once the current recomposition completes
v
I used to be a reasonably competent developer. Moving into management has dulled those senses. Or maybe I just don't understand Compose.
😁 1
p
Compose has its own lifecycle stuff. Not quite the same as the Activity lifecycle but more related to entering/exiting the composition tree. But still lifecycle somehow. Actually back to Activities lifecycle it has its similars in other platforms too. UiViewController didViewApper and willViewAppear in iOS, minimize/restore desktop and Web
v
Copy code
LaunchedEffect(state){
        println("State changed: $state")
        window.title = "Corbel Editor: ${state.value.mode.name}"
    }
I thought this would be 'fired' every time
state
changes (where
val state = viewModel.appState.collectAsState()
. Though to be honest I don't know what needs to change for this to count as a.... change? Because calling
state.appState.mode=Mode.BUSY
definitely doesn't count.
So yeah, I don't understand State.
p
Use
by
instead of
=
or, collectAsState(). value You are keying LaunchEffect with an instance var that doesn't seem to change. If they doesn't change the effect won't retriger