Hi Guys I need help with understainding how flow w...
# flow
b
Hi Guys I need help with understainding how flow works. Basically I have this flow inside of ViewModel:
Copy code
private val selectedCategorySource = MutableStateFlow(ArticleCategory.NotSelected)
val articles: Flow<PagingData<Article>> = selectedCategorySource
        .flatMapMerge {
            if (it != ArticleCategory.NotSelected)
                repo.getArticles(it).cachedIn(viewModelScope)
            else
                flowOf(PagingData.empty())
        }
I'm observing it inside of fragment like that:
Copy code
lifecycleScope.launch {
    repeatOnLifecycle(Lifecycle.State.STARTED) {
        viewModel.articles.collect {
            articleListAdapter.submitData(it)
        }
    }
}
Problem: When selectedCategorySource is changed to NotSelected PagingData.empty() is not collected by fragment. Any ideas why it might be happening?