Timo Drick
01/28/2021, 3:04 PMval list = remember(snapshotStateList) {
snapshotStateList.filter { removed.contains(it).not() }
}
Timo Drick
01/28/2021, 3:10 PMval list = remember(snapshotStateList.size) {
snapshotStateList.filter { removed.contains(it).not() }
}
Paul Woitaschek
01/28/2021, 3:14 PMit !in removed
Adam Powell
01/28/2021, 3:42 PMval filteredList by remember(snapshotStateList, removed) { derivedStateOf { snapshotStateList.filter { it !in removed } }
?Timo Drick
01/28/2021, 3:55 PMAdam Powell
01/28/2021, 3:59 PMderivedStateOf
is kind of like mutableStateOf
, except it returns a read-only snapshot State<T>
that always contains the latest value of the lambda expression it was constructed with. It caches the result of this computation. If the derived state block reads other snapshot state, the derived state object will invalidate its cache whenever the state it had to read changes.Adam Powell
01/28/2021, 4:00 PMAdam Powell
01/28/2021, 4:02 PMremember
that derived state object and use by
property delegation just like we do with mutableStateOf in composition. We use the snapshot state list and the removed list as remember keys, so we create a new derived state object if we change the whole lists it's based on.Timo Drick
01/28/2021, 4:02 PMAlexander Sitnikov
01/28/2021, 4:11 PMsnapshotStateList
is mutable, and when SlotTable compares remembered value with new value when snapshotStateList
changes, it sees no difference, because it's the same object?Adam Powell
01/28/2021, 4:46 PMremoved
collection changing.)Dominaezzz
01/28/2021, 8:01 PMderivedStateOf
didn't need to be remembered. TIL.Timo Drick
01/28/2021, 9:14 PMDominaezzz
01/28/2021, 9:43 PMremoved
(and maybe snapshotStateList
) in the remember
keys, shouldn't derivedStateOf
handle that already?Adam Powell
01/29/2021, 12:08 AMderivedStateOf
lambda closes over the collection instances of snapshotStateList
and removed
. If the actual collection instances change, we need to create a new derivedStateOf
to observe those new collections.Adam Powell
01/29/2021, 12:09 AMremoved
is either another snapshot state list where the derivedStateOf can observe changes to it or immutable (so that the remember keys will result in a new derived state object if it does change)