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

nglauber

07/05/2020, 2:58 PM
How can I change my state without pass a callback deep down into my composable “hierarchy”. I mean… I have a state on my composable
A
and this composable calls
B
which calls
C
. Is there a way to change the state in
C
? When we had
@Model
we just need to update attribute and it worked…
👀 1
a

Adam Powell

07/05/2020, 3:29 PM
@Model
is functionally equivalent to:
Copy code
@Stable
class MyState {
    var one by mutableStateOf(0)
    var two by mutableStateOf("default")
        private set
    // ...etc
}
if you have a pattern that worked well with
@Model
the above transformation will behave the same* way *the above will update more granularly based on individual property reads and changes, whereas
@Model
would update any property reader scope even if that scope only read properties that did not change.
👍 1
(the
@Stable
is there for some specific skipping optimizations, presuming that all state in the object obeys the stability contract like
MutableState<T>
or immutable values do. We're hoping to infer it automatically later.)
n

nglauber

07/05/2020, 4:37 PM
Thanks @Adam Powell 🙏 It worked 😉
👍 1
2 Views