How much of a crime would be to do something like ...
# compose
a
How much of a crime would be to do something like
val _composables_  = _MutableStateFlow_<List<@Composable () -> Unit>>(_emptyList_())
?
😁 1
p
I don't see any wrong doing, at first sight
j
Seems fine. You probably don't need a state flow, though. Return
@Composable { for (lambda in lambdas) lambda()
and encapsulate the state list. Compose will recompose when it changes, and your consumers only get a single composable lambda to put wherever. No collection or iteration at the consumption site, just a single invocation
👍 1
a
Thanks. I am currently working on a screen whose content is defined by the backend, so I trying to figure how to convert the BE output to composables.
j
Mutating a MutableStateList of Compose lambdas would be a good solution. No need for a state flow. Mutate the list and Compose will react to its changes
a
Thanks @jw
p
Oh interesting, I am working on a similar concept. The only way I have found is either using polymorphism , sort of:
Copy code
interface Component {
  @Composable
  fun View()
}
Or without polymorphism, having a huge Composable mapper function that basically does this:
Copy code
@Composable
fun genericRenderer(
serverComponentMetadata ComponentMetadata
) {
when(serverComponentMetadata) {
  Component1 -> Component1Composable(
serverComponentMetadata
)
  Component2 -> Component2Composable(
serverComponentMetadata
)

...
}
}
But this map tends to grow huge and also calling this function pretty much everywhere sounds repetitive. Haven't found any other alternatives.