fix: StaffDataRepository.staff getter returns new instance each calls #674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview (Required)
ブログを書いていたら、
StaffDataRepository
に2つの問題があるコードを見つけたので報告しておきます。アプリの動作には問題となって表れない issue です。
1.
loadStaff()
を呼ばなくてもstaff
の getter で検索処理が実行されるloadStaff()
で検索処理が実行され、staff as Flowable を通じて結果が通じると期待しましたが、loadStaff() を呼ばずに staff プロパティを取得するだけで検索処理が実行されてしまいます。なので、スタッフ画面の起動時に、スタッフ検索処理(
getStaff()
)が2回実行されていました。2. staff プロパティは get する度に新しい
Flowable
のインスタンスを生成してしまうstaff
の getter や、loadStaff()
を呼ぶ度に Flowable インスタンスが再生成されています。このため、
StaffViewModel
側の受信処理でと定義しても、その時の
repository.staff
は次回のloadStaff()
呼び出しで使われなくなってしまうので、結果として、loadStaff()
を2度目以降の呼び出しにはStaffViewModel.staff
は無反応になります。アプリのスタッフ画面はloadStaff()
が意図して複数回呼び出されるケースがないので、こちらも顕在化しません。