android10 / android10/Android-CleanArchitecture-Kotlin

Should we use instance variables inside a ViewModel to reuse fetched data?

Aperta
#84 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
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.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.