Why onEach instead of collect {} #846
Unanswered
mobilekosmos
asked this question in
Q&A
Replies: 3 comments
|
I'm curious about this too. I did find a session from the Android Dev Summit 2021 where they mention the use of Also, I stumbled upon this discussion post while wondering why we don't use lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState
.collectLatest { uiState = it }
}
}Hoping for anyone with more experience in Kotlin Flows to comment on whether this is a valid (and better) code. |
0 replies
|
I think it's written that way when he considers a lot of maintenance of functions. |
0 replies
|
@ParkJong-Hun |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to learn best practices and I'm not sure why you are using in the MainActivity .onEach instead of just simply using collect {} directly, just personal preference?
All reactions