Hello everyone, Recently, I've been studying compo...
# compose
n
Hello everyone, Recently, I've been studying composites and I had a question. As far as I know, the lambda is always considered stable by the Compose compiler. However in the following example the lambda looks it should not be considered stable. But in my observation the compiler decides it as stable which may delay the application of variable
x
. Is it an intended behavior or a bug?
Copy code
class TestClass {
    val test: @Composable () -> Unit = {
        Text(x)
    }
}
var x = "not init text"

@Composable
fun TestTest(testClass: TestClass) {
    testClass.test()
}
cases are roughly written to find edge cases.
a
Lambda stability depends on references captured inside it. Probably mutable variable is not considered stable. Try changing
var x
to
val x
. Nvm, lambda is a class field, this is probably some different case
n
Sorry I've updated my question to make it clear. @Alexander Zhirkevich
a
If you want to call resomposition when variable x changes you should use State
var x by mutableStateOf("..")
n
Oh, I know about that point (thanks 👍). but I think If there is such a case like that, I wonder if it shouldn't be treated as stable.
If compiler judge lambda stablilty by the captured values, I think the following cases are also possible.
Copy code
class TestClass {
    val test: @Composable () -> Unit = {
        var x = "not init text"
        AnyGlobalObject.addAction {
            x += "!!"
        }
        Text(x)
    }
}