Se7eN
10/07/2020, 9:50 AMliveData
builder before like this:
val users = liveData {
emit(getUsers(count=20))
}
With StateFlow, I'm doing it with `lazy`:
val users by lazy {
MutableStateFlow<List<User>>(listOf()).also { usersFlow ->
viewModelScope.launch {
usersFlow.value = getUsers(count = 20)
}
}
}
Just wanna know if it's fine to do it this way?Erik
10/07/2020, 10:51 AMMutableStateFlow(...).onStart { emit(getUsers(count = 20)) }
?Se7eN
10/07/2020, 10:54 AMcollect
after the onStart
but that's not how I'm doing it. Also onStart
converts it to Flow
so I can't add that while initializingErik
10/07/2020, 10:57 AMSe7eN
10/07/2020, 11:02 AMStateFlow.collectAsState
but the onStart
never runs. Is this a bug?Erik
10/07/2020, 11:37 AMSe7eN
10/07/2020, 11:40 AMonStart
never gets calledErik
10/07/2020, 11:41 AMSe7eN
10/07/2020, 11:43 AMErik
10/07/2020, 1:16 PMSe7eN
10/07/2020, 1:17 PM