android / sunflower

A gardening app illustrating Android development best practices with migrating a View-based app to Jetpack Compose.
https://d.android.com/jetpack
Apache License 2.0
17.58k stars 4.67k forks source link

Mixing LiveData with ObservableField #115

Open Malachiasz opened 5 years ago

Malachiasz commented 5 years ago

Don't you think it's better to stick to one or the other? What benefits gives using them both in one project?

XinyueZ commented 5 years ago

ObservableField -> data-binding, for property level, not be played as event-handler. LiveData -> interactions between ViewModels and other components or ViewModels or classes, like event-handlers. These r my opinions, they are two different concepts. Of cos, LiveData is observable.

Malachiasz commented 5 years ago

@XinyueZ ObservableField could be a subset of LiveData, as LiveData does exactly what ObservableField does plus is aware of LifecycleOwner and has convinience method for setingField on Main thread. I don't see the reason why to use them both. It's exactly the same concept, except that databinding.Observable removes Obdervable through generated code and LiveData through code which is there.