But in above scenario - this code particularly
@Composable
fun MyTopLevelComposable(viewModel:MyViewModel){
when (val state = viewModel.response.observeAsState().value) { // observing live-data state
is Content -> LaunchedEffect(Unit) { launchActivity() }
Error -> SideEffect { someDialog.value = true}
}
}
It will never get recomposed. The only reason for this composable to be called again could be if compose compiler invalidates the view.
My Query is -> when view/composable gets
invalidated
SideEffect {someDialog.value = true}
executes, because it will again go through
composition
not
re-composition
as
viewModel.response(which is live-data)
last state was
Error
But if change it to
LaunchedEffect(Unit) {someDialog.value = true}
it doesn't executes again after the composable is invalidated. It only reacts to a new state emitted by the live-data.
Question is why?
Invalidate
should start composition again, and since it's a composition. not re-composition
LaunchedEffect
should behave similarly to
SideEffect
in this scenario, as both are reaching to composition.
Or May be i am missing something here?