android10 / android10/Android-CleanArchitecture-Kotlin
Should we use instance variables inside a ViewModel to reuse fetched data?
- Lingua principale
- Kotlin
- Stelle
- 4.8k
- Fork
- 929
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
What is the best approach?
```
// Only expose livedata
public class MyViewModel extends ViewModel {
private MutableLiveData> users = new MutableLiveData();
public void loadUsers() {
// Do an asynchronous operation to fetch users.
users.postValue(/* ---- userList --- */);
}
}
```
```
// Expose livedata and instance variable userList
public class MyViewModel extends ViewModel {
private MutableLiveData> users = new MutableLiveData();
private List userList;
//Expose already fetched list
public List getUserList() {
return userList;
}
public void loadUsers() {
// Do an asynchronous operation to fetch users.
this.userList = userList;
users.postValue(/* ---- userList --- */);
}
}
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.