android10 / android10/Android-CleanArchitecture-Kotlin
Should we use instance variables inside a ViewModel to reuse fetched data?
- Linguagem predominante
- Kotlin
- Estrelas
- 4.8k
- Forks
- 929
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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 --- */);
}
}
```
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Avaliação
Esta issue ainda não foi avaliada.