Colton Idle
07/15/2023, 1:32 AMLaunchedEffect(key1 = viewModel.appState.items, block = {
viewModel.refreshDataThatDependsOnItems)
})
but now that I added logs, I can see that even though the size of items changes from 0 to 100, the refresh() never gets called. If I update to
LaunchedEffect(key1 = viewModel.appState.items.size, block = {
then everything works correctly.
items is defined in the VM as var items = _mutableStateListOf_<Item>()
I ask because I have cases where the size of items could actually stay the same, but the data was different, and so I'd like to make sure I call refresh() againshikasd
07/15/2023, 1:45 AMmutableListOf
instead of mutableStateListOf
, as state list doesn't add any magical behavior outside of observation.
You probably want to use items.toList()
as a key insteadColton Idle
07/15/2023, 1:47 AMColton Idle
07/15/2023, 1:56 AMColton Idle
07/15/2023, 4:03 AMval myStateFlow = viewModel.appState.myStateFlow.collectAsState()
LaunchedEffect(myStateFlow.value?.items)
or would I do
LaunchedEffect(myStateFlow.value?.items?.toList())
my models:
private val _myAppState: MutableStateFlow<AppState?> = MutableStateFlow(null)
val myAppState: StateFlow<AppState?> = _myAppState
data class AppState(
val items: List<Long>
)
so the only thing that's "observable" is the top level appState, so I don't think I should be able to "observe" a list in a LE, can I?Stylianos Gakis
07/15/2023, 7:52 AM