LiveData or StateFlow? I don't understand why peop...
# flow
c
LiveData or StateFlow? I don't understand why people use StateFlow. And there's flow for Repository. I am very confused. Anybody can make me understand them...?
c
You can't use LiveData server-side, in a JVM Desktop application, in your JS website, or in iOS.
c
So, LiveData is just for android and StateFlow for other platforms?
That's interesting that server side also uses StateFlow. Does it need to observe data?
c
StateFlow is not for "other platforms". It's for all platforms, you only need to learn one thing and use it everywhere.
Does the server need to observe data?
Depends on your server. I use flows to cache frequent DB requests in-memory → https://gitlab.com/opensavvy/pedestal/-/blob/main/cache/src/commonMain/kotlin/Cache.kt
Since flows are multiplatform, I can use the same Cache implementation server-side to cache the DB and in the JS code to cache network requests. There's no need anymore to reinvent the wheel on every app.
c
That's a good point. Thanks for the explanation. 🙂
f
Also Google mentions it's not necessary to mix LiveData with Flows when using Compose etc...they specifically say using LiveData isn't necessary and just an extra thing. Consuming a Flow from a Composable seems a bit cleaner to me than LiveData as well, and it goes along with the Compose MVI architecture
c
For me, it's very confusing. It'd be nice if there are commonly used template or something.. I feel like I need to use flow and StateFlow but it's hard to apply..
f
There are! check out the Google sample projects