If I try to do `snapshotFlow { mySnapShotStateLis...
# compose
c
If I try to do
snapshotFlow { mySnapShotStateList}.collectLatest{ //Log.e("UPDATE")}
I won't get updates unless I do
snapshotFlow { mySnapShotStateList.toList() }.collectLatest{ //Log.e("UPDATE")}
Yet when I go to use a lazy column or column I don't have to call
toList()
. Is there any way to know when I'll have to call .toList() to get proper observability as I intended?
z
Something has to actually read the state object. Merely referencing it isn’t reading it
❤️ 2
Lazy lists need to read the list because they iterate over it, check its size, etc
Your case as written is probably gonna be awkward regardless because you’re not actually using any of the data from the list, so there’s no obvious read operation to perform. If you just want to log when the list changes, you can avoid making a copy of the whole list with something like:
Copy code
snapshotFlow {
  mySnapShotStateList.size
  Log.e("UPDATE")
}.collect()
u
@Colton Idle In the case of
snapshotFlow
the recommended pattern is indeed to use
SnapshostStateList.toList()
, your use case is why that method was added. It does not make a copy of the list, but uses the immutable/persistent list that it maintains for snapshot state, so no worries.
nice spin 1
c
awesome! thanks everyone. learned something new