-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Missing StateFlow operators #2008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think using That way you can do more transformations between the two |
Where can I find more information about stateIn? Can't find it in the docs. |
@NahroTo |
The design of |
@elizarov What if I want to simply transform with |
@brescia123, updating the return type is a breaking change. |
We are on transit from LiveData to StateFlow, because it allows us to write more declarative code. It also means we are writing many chains. However, many state flows have Just an idea, but maybe it is worth considering implement non-suspendable version of few operators, who guarantee the result will be correct. For example |
@neworld Can you, please, elaborate a bit on what you mean by "fragment can't consume suspendable version" and give some examples of the code you are having to write in your app. |
@elizarov, sorry for my long delay.
This is a tricky part because fragment actually could consume suspend functions because it has scopes. But it is more UX/philosophical problem rather than a technical one. Fragments always have to show some state and a blank screen is not desired behavior. I didn't tried, but Jetpack Compose should not be compatible with suspended state (collectAsState). But to be honest, I can't find any big problem in ViewModel to use
For longer chains, it is harder to follow, because the initial item is at the end of the chain. But put ViewModel aside. The real problem we are facing is inside scopeless helper classes:
What is a best practice here? Some ideas we have:
|
I'm missing operators for
StateFlow<T>
such as map and transform. Example use case:This would be the same API Android's LiveData provides.
The text was updated successfully, but these errors were encountered: