oday
10/06/2022, 11:57 AMdata class EventsState(
val events: List<EventComponent> = listOf(),
val isLoading: Boolean = true,
val errors: Errors = Errors.None
)
back in my switch case, I have a case for isLoading
, another case for events.isNotEmpty()
, another for errors.throwable != null
and the final else
where I’m assuming the events list is empty
the issue is, when I first load up, and while the events list is coming back, I get the empty state
why is that? isLoading
starts off as true and the only time it becomes false is when the events come back, I update the state along with the isLoading in 1 go, when is it getting the chance to fall into the else?
eventsState.value =
eventsState.value.copy(events = it, isLoading = false, errors = Errors.None)
AmrJyniat
10/06/2022, 12:59 PMAhaisting
10/06/2022, 2:22 PMsealed
class, in my eye! A friend of mine wrote an article about this a while ago:
https://medium.com/livefront/tidy-up-your-observable-streams-with-kotlins-sealed-classes-ce7bdce9c270oday
10/06/2022, 2:27 PModay
10/06/2022, 2:31 PMAhaisting
10/06/2022, 2:32 PMsealed class
is probably my favorite kotlin feature… it allows you to write models in a way where invalid state is impossible 🙂oday
10/06/2022, 3:10 PModay
10/07/2022, 10:00 AModay
10/07/2022, 10:02 AMAhaisting
10/07/2022, 2:05 PMdata
class, you can still use copy