https://kotlinlang.org logo
#compose
Title
# compose
a

Alexander Karkossa

12/20/2020, 10:46 AM
Any plannings for adding these function?
<R, T : R> LiveData<T>.observeAsState(initial: R, *policy: SnapshotMutationPolicy<R>*): State<R>
a

Adam Powell

12/20/2020, 2:59 PM
No plans to so far. What's your use case?
a

Alexander Karkossa

12/20/2020, 6:05 PM
Maybe very special case.
LiveData<List<Person>>
from Database. List which shows persons, markable as favourite. The Person is not immutable so you set
isFavourite = true
. Insert it into Database. -> The View will not recompose. Reason: Because of the EqualityPolicy. isFavourite is already true in that person. Workaround 1 (seems best/the way we use it at the moment): Make person immutable -> call:
db.insert(person.copy(isFavourite  = true))
Workaround 2: Don't use
data class
which generates these smart equals methods... Thought: Maybe the are cases where i would change the policy simmilar to the mutableStateOf()
a

Adam Powell

12/20/2020, 6:48 PM
Yeah I agree with immutable being the best answer in this case