my state contains list of feeds, selected feed and posts related to selected feed.
every time feed is selected, I want to fetch/observe it’s posts.
I tried doing it like this:
Copy code
val posts by snapshotFlow { selectedFeed }
.filterNotNull()
.flatMapLatest { observePostsUseCase(feedId = it.id) }
what happens is that
snapshotFlow
emits same item 6, 7 times, even if I put
.distinctUntilChanged
into the chain.
should
snapshotFlow
emit only when
selectedFeed
changes?
I thought maybe my feed class
equals
isn’t right but it works properly.
a
Albert Chang
06/22/2024, 2:19 PM
You need to remember the flow, otherwise each recomposition will create a new flow.