https://kotlinlang.org logo
s

Sam Stone

01/04/2023, 2:31 AM
Are there any coroutine-friendly observer pattern implementations?
LiveData
is great but only for Android.
t

Trevor Stone

01/04/2023, 2:50 AM
Flow?
r

Riccardo Lippolis

01/04/2023, 7:40 AM
More specifically, you might be looking for a StateFlow
g

gildor

01/04/2023, 7:41 AM
To be honest, LiveData is not great for Android too
k

Kevin Del Castillo

01/04/2023, 2:00 PM
LiveData is great until you discover Flows 😆
s

Sam Stone

01/06/2023, 4:36 AM
@gildor so why is it part of the officially recommended app architecture?
g

gildor

01/06/2023, 4:50 AM
Because they couldn't recommend a much more superior, but complex library like RxJava (which also requires another third party lib to work with Android) And now Flow is officially supported by all Androidx API, and thought LiveData is officially not deprecated or discouraged (also Flow will not work in Java anyway), I don't see reason to use it Nothing against LiveData itself if you consider that Android needed some simple and safe solution for observable properties, but I would use it only if would be no alternatives, which we do have and one of them is officially supported
s

Sam Stone

01/14/2023, 11:57 PM
In the google Android codelabs, the repository often returns a flow from the database, and the ViewModel returns
flow.toLiveData()
.
g

gildor

01/15/2023, 1:25 AM
Well, codelab is just a codlab, unclear when it was updated and it may have own requirements LiveData used to have a couple unique useful semantics, like it stopped collection onStop lifecycle, but now there is official flowWithLifecycle for this, so there is no real difference. Nothing wrong with using LiveData, I just don't understand why
s

Sam Stone

01/15/2023, 2:30 PM
Good to know about flowWithLifecycle!
86 Views