Replies: 9 comments 5 replies
-
@luongvo I agree for using launchIn and refactoring flowTransform. But I'm not sure about For this implementation: @Composable
fun <T> Flow<T>.collectAsEffect(
context: CoroutineContext = EmptyCoroutineContext,
block: (T) -> Unit
) {
LaunchedEffect(key1 = Unit) {
onEach(block).flowOn(context).launchIn(this)
}
}
|
Beta Was this translation helpful? Give feedback.
-
@luongvo It's good to bring these improvements to the team in the discussion. There are 3 different topics so quite inconvenience when we have to point out which one we agree and disagree IMO 😄 Agree with this. This is convenient when we need to collect events from Flow, especially in the ViewModel layer 👍
I think @lydiasama's concern is valid, the
No more concern from me, as I remember we discussed this before. |
Beta Was this translation helpful? Give feedback.
-
I agreed with @lydiasama concern for
All good to me 👍 |
Beta Was this translation helpful? Give feedback.
-
FYI: We can update the |
Beta Was this translation helpful? Give feedback.
-
@lydiasama @hoangnguyen92dn @kaungkhantsoe @Wadeewee I think you all agreed to have some extensions to optimize our Kotlin Coroutines & Flow usage. Let's not go too deep into the implementation detail in this RFC and discuss more in the implementation PR instead. What do you think? If yes, please vote for the RFC, and I'll start creating tasks for this. Many thanks 🤗 |
Beta Was this translation helpful? Give feedback.
-
@ryan-conway I think I received enough votes. More discussions would be raised in the final implementation PRs 💪 I'm going to create 3 separate issues for this. |
Beta Was this translation helpful? Give feedback.
-
@luongvo Cool! Voted 🚀 Will the extension function for Compose be added to |
Beta Was this translation helpful? Give feedback.
-
@Tuubz @hoangnguyen92dn it requires Compose API, so at least we need to separate it into a separate lib as an option instead, like
That is a separate action from my task 🤷♂️ |
Beta Was this translation helpful? Give feedback.
-
Issue
We applied using Kotlin Coroutines & Flow in our template and client projects for a while. During that time, there is a room for improvement with more excellent extensions, better approaches, or shorter callers. We should consider refactoring & optimizing them for our templates.
Solution
In this RFC scope, I would like to raise some points to apply:
Using
launchIn
instead ofcollect
for collecting Flows.References:
Defining some valuable extensions for Compose to reduce boilerplate code
collectAsEffect
References:
Refactor
flowTransform
extension to userunCatching
and get rid oftry/catch
with generic exception caught.Who Benefits?
Developers
What's Next?
6 votes ·
Beta Was this translation helpful? Give feedback.
All reactions