I have to load reviews based on storeURL and the SKUs of the products. For SKUs I make a network call and get the products in a MutableFlow. The storeURL is in a compositionLocal. Now, how do I pass this storeURL from composition local to the viewModel.
This is the function for loading reviews in viewModel
fun loadReviews(products: List<Storefront.Product>?, storeUrl: String) {
viewModelScope.launch(Dispatchers.IO) {
when (val result = getReviews(products, storeUrl)) {
is Resource.Loading -> Unit
is Resource.Success -> {
val data = result.data
data.whatIfNotNull {
reviews.value = it
}
}
is Resource.Error -> Unit
}
}
}
This is how I want to do it in the init block
init {
viewModelScope.launch {
productsList.collectLatest { products ->
loadReviews(products, [HOW TO GET STORE URL FROM COMPOSITION LOCAL HERE])
}
}
}