android10 / android10/Android-CleanArchitecture-Kotlin

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

オープン
#84 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Kotlin
スター
4.8k
フォーク
929
PR マージ指標
30日以内にマージされた PR はありません

説明

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 --- */);
}
}
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。