Raphael TEYSSANDIER
05/03/2023, 6:11 PMuiState
in compose. With a list of product, and listen on execution of those product and update the UI in consequence.
private fun StateFlow<List<Product>>.toItems(): Flow<List<HomeItem>> {
return map { products -> ... }
.transformLatest { products ->
if (products.isEmpty()) {
emit(emptyList())
} else {
combine(
products.filter(Product::isNotEmpty)
.map { product ->
combine(
product.refreshObs.asFlow(),
executionStateOf(product.id)
.onStart { println("FlowTest Execution onStart") }
.onCompletion { println("FlowTest Execution onCompletion") }
.onEach { println("FlowTest Execution onEach") }
) { _, data ->
println("FlowTest Combine result")
product.toItem(data)
}
.scan(product.toItem(Data.Empty)) { _, item ->
item
}
},
Array<HomeItem>::toList
)
.collect {
emit(it)
}
}
}
}
But the executionStateOf
is cancelled with child of the scoped flow was cancelled
executionStateOf
is a MutableSharedFlowLeo Delon
05/04/2023, 8:14 AMList<Product>
to List<HomeItem>
using only operators. I noticed when I tried collecting and updating some other flow, my nested combine went inactive and therefore cancelled.Raphael TEYSSANDIER
05/04/2023, 3:18 PM