abbic
08/22/2022, 12:25 PMviewmodel.events.observe { when (event) etc etc }
now my instinct is to have the events be a val on the uiState like
UiState(val event)
and then in the composition
SomeScreen(uiState) {
LaunchedEffect(uiState.event) {
when (event) etc etc
}
}
but this causes a problem where in livedata you could post the same event in a row multiple times and the observer would trigger each time.
i have to assume that if you copy the uiState and set the same event now the LaunchedEffect wont trigger. I can clear the event manually in the state each time, but the slight overhead makes me wonder if there's a better way to do it?Filip Wiesner
08/22/2022, 12:27 PMSharedFlow
for this.LaunchedEffect(eventFlow) {
eventFlow.collect { event ->
when(event) { ... }
}
}
abbic
08/22/2022, 12:32 PMAle Stamato
08/22/2022, 3:28 PMFilip Wiesner
08/22/2022, 4:30 PMFrancesc
08/22/2022, 6:21 PMLaunchedEffect
on the list, handle one, tell the viewmodel you handled it, the viewmodel will remove it from the list and your LaunchedEffect
will trigger again so you can handle the next