https://kotlinlang.org logo
#compose
Title
# compose
g

Grégory Lureau

06/13/2022, 9:48 PM
Trying to run molecule with CfD (copied the runtime methods as there is no build yet for JVM), looks like it's always recomposing and remember call the `calculation`on each composition. Any advice?
Copy code
@Composable
fun testMolecule(): Int {
    var value by remember { mutableStateOf(0) }
    LaunchedEffect(Unit) {
        value += 1
    }
    return value
}
Copy code
val coroutineScope = rememberCoroutineScope()
val lastValue = coroutineScope.launchMolecule {
    testMolecule()
}
println("lastValue=${lastValue.value}")
-> print "lastValue=0" on every frame. With this code I'm expecting value to be 1 and no recomposition.
j

james

06/13/2022, 10:30 PM
I don’t have an answer for you, but a bunch of the Square and CashApp teams hang out in #squarelibraries and may be able to assist
j

jossiwolf

06/13/2022, 10:38 PM
How are you calling
launchMolecule
? That looks like you're calling it in a Composable?
g

Grégory Lureau

06/14/2022, 6:50 AM
Yes @jossiwolf I'm calling it from a Composable function for the view. I plan to put the
testMolecule()
function in a class (VM) and call it from the view to have my state. Is it forbidden?
2 Views