android / android/architecture-samples
[master][suggestion] Boilerplate code with LiveData accessing modifiers
- Dominant language
- Kotlin
- Stars
- 45.8k
- Forks
- 11.9k
- PR merge metrics
- No merged PRs in 30d
Description
Doing such duplicates for hiding external modifications just looks wrong. Is anything we can do with it?
```
private val _empty = MutableLiveData()
val empty: LiveData = _empty
```
We understand, it's should be clear for all, where this **Mutable** `LiveData` should not be visible from outside. However, as mentioned in the README page, it's should be as reference for developers. And it's not a reference for usual project, where this boilerplate code may be avoided somehow, with wrapper on reading only value, or something else like invoking to do mutable.
```
abstract class BaseViewModel : ViewModel() {
operator fun LiveData.invoke() : MutableLiveData {
return this as MutableLiveData
}
}
// ...
val empty : LiveData = MutableLiveData()
// ...
// To make visible, just invoke variable. Works only inside BaseViewModel
empty().value = tasks.isNullOrEmpty()
```
To keep it, as pure valuable reference for a new project, could we try to do something with it?
Regards,
Contributor guide
Research direction
Start by reviewing the README page and its LiveData example, then inspect the surrounding architecture-samples documentation and sample usage. The issue proposes alternatives but does not identify a target file or accepted design; done would require an agreed approach that removes or justifies the boilerplate in the reference example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100