Giving it a try now... but I'm getting an error in...
# squarelibraries
d
Giving it a try now... but I'm getting an error in Android Studio that flow operators shouldn't be used in composables... will I have to do
@SuppressLint("FlowOperatorInvokedInComposition")
for each of them? It seems to me that in the context of Molecule presenters there's no real problem in transforming/filtering flows... maybe there's a way for the library to suppress those warnings for it's functions somehow?
h
You should use
collectAsState
instead.
d
Copy code
val installState by applicationStatus
    .filter { it.packageName == summary.packageName }
    .flatMapLatest { it.progressFlow }
    .collectAsState(initial = InstallState.None)
Gives me that error
The filter and flatMapLatest bothers AS...
j
It needs remembered
d
Then I get
Composable calls are not allowed inside the calculation parameter of inline fun <T> remember(crossinline calculation: () -> TypeVariable(T)): TypeVariable(T)
on collectAsState
j
collectAsState goes on the outside
You want to remember the computation of the Flow
And then collect that final flow in the composition
h
Copy code
val installState by remember { applicationStatus
    .filter { it.packageName == summary.packageName }
    .flatMapLatest { it.progressFlow } }
    .collectAsState(initial = InstallState.None)
d
👍🏼
Thanks! And now I don't need to suppress any IDE warnings... AND I learned that even Molecule needs remember... it feels funny since in a
ViewModel
you don't usually need it, and in the docs, there's no mention of it.
h
Yeah, but this is unrelated to molecule, just the basic behaviour of compose and recomposition on state changes
j
It's not Molecule, it's performing unnecessary computation on each composition. Any flow would need it.
579 Views