Hello, is it possible to call a collect in a collect?
I have this code:
Copy code
dateFlow.collectLatest { date ->
repository.getContentFromDate(date).collect { result ->
I can change the date so the content update.
But I have a favorite feature on the content.
On the default date, the favorite is working well (I collect the new value) but when I update the date, the collect doesn’t work on favorite events.
What am I doing wrong?
Thanks.
e
ephemient
11/30/2021, 9:05 PM
you probably want to do
Copy code
dateFlow
.flatMapLatest { date ->
repository.getContentFromDate(date)
}
.collect { result ->
which will cancel the previous
repository.getContentFromDate
collection on each new
date
j
joadar
11/30/2021, 9:11 PM
Thanks, but still the same issue.
I update dateFlow this way:
Copy code
private val dateFlow: MutableStateFlow<Date> = MutableStateFlow(currentDate)
...
dateFlow.update {
date
}
Aaaaaaah, my bad I managed the data in a specific way and I forgot to branch the data from Room during my network call (I saved the network content in room but I was returning the network “static” content and not the database content)
joadar
11/30/2021, 9:20 PM
Thank you @ephemient for your help. At least the method you shared make it cleaner.