Dzmitry
05/17/2024, 10:55 AM@Stable
annotation. Is there any sense in it? Isn't this annotation only applicable for composable functions?Alexander Zhirkevich
05/17/2024, 11:28 AMDzmitry
05/17/2024, 11:33 AMAlexander Zhirkevich
05/17/2024, 11:50 AMAlexander Zhirkevich
05/17/2024, 12:07 PM@Composable
fun App() {
Something(foo(1))
Something(bar(2))
}
class IntWrapper(
val value : Int
)
@Composable
fun Something(intWrapper: IntWrapper) {
println(intWrapper.value)
}
@Stable
fun foo(x : Int) = IntWrapper(x)
fun bar(x : Int) = IntWrapper(x)
Something
will be skipped during recomposition if its parameter is a result of a stable functionDzmitry
05/17/2024, 12:32 PMAlexander Zhirkevich
05/17/2024, 12:53 PMequals
result of 2 "equal" instances to always be true
. It must always be "the same" (as i understand from the docs). When the 1st rule is fulfilled, function annotation is probably redundant. It is my guess, it can be wrongAlexander Zhirkevich
05/17/2024, 1:01 PMequals
is not implemented or class is not immutableDzmitry
05/17/2024, 1:01 PMAnkit Kumar
05/17/2024, 4:47 PMAnkit Kumar
05/17/2024, 4:48 PMSomething
being skipped then it will always skip until intWrapper
changesAnkit Kumar
05/17/2024, 4:50 PM@Composable
private fun Demo() {
Column {
var state by remember { mutableStateOf(3) }
Block(result = foo(2))
Text(text = "hey $state")
Button(onClick = { state++ }) {
Text(text = "recompose")
}
}
}
@Composable
private fun Block(result: Result) {
println("foo recomposing Block")
Text(text = "result inside ${result.x}")
}
@Stable
fun foo(x: Int): Result {
println("foo calculating foo")
return Result(x)
}
data class Result(var x: Int)
if we go as per what discussed above since foo
method calculating Result
is Stable so Block
should skip but it will not bcz Result
is unstable
but if I remove Stable from foo and make Result Stable it will skip