is this not how I would observe the changes in these MutableStateFlows?
Copy code
private val categoryFilter = BrowseEventsFilter.CategoryFilter(category = MutableStateFlow(Category.All))
private val locationFilter = BrowseEventsFilter.LocationFilter(location = MutableStateFlow(null))
private val periodFilter = BrowseEventsFilter.PeriodFilter(
period = MutableStateFlow(Period.Any),
dateRange = MutableStateFlow(null)
)
and then you change them
Copy code
var filtersState = MutableStateFlow(listOf(locationFilter, periodFilter, categoryFilter)) // collectAsState in the activity
// how they change
filterState?.enabled?.value = ChipStatus.ENABLED
filterState?.period?.value = period
filterState?.dateRange?.value = null
and then observe them
Copy code
flowOf(periodFilter.period?.value,
periodFilter.dateRange?.value,
categoryFilter.category.value,
locationFilter.location.value
).collect {
// do something everytime their values change
}
f
Filip Wiesner
11/15/2022, 12:24 PM
You are just creating a flow that will emit 4 values and stop. Look at the
flowOf
implementation:
Copy code
public fun <T> flowOf(vararg elements: T): Flow<T> = flow {
for (element in elements) {
emit(element)
}
}