Trying to run molecule with CfD (copied the runtim...
# compose
g
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
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
How are you calling
launchMolecule
? That looks like you're calling it in a Composable?
g
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?