Noé Casas
01/20/2021, 7:35 AMMutableState
stored as a member of an object retrieved through an Ambient, like this:
data class ServiceX (
val whateverString: MutableState<String>("meow")
)
@Composable
fun Whatever() {
val serviceX = AmbientServiceX.current
Text(serviceX.whateverString)
}
Will the Composable function repaint when whateverString
changes? Are there any problems with this?jim
01/20/2021, 10:14 AMNoé Casas
01/20/2021, 1:46 PMAdam Powell
01/20/2021, 3:00 PMNoé Casas
01/20/2021, 3:16 PMAdam Powell
01/20/2021, 3:53 PMServiceX
as something more like:
class ServiceX(whateverString: String) {
var whateverString by mutableStateOf(whateverString)
private set // optional, but often useful!
// ...
}
with the key distinction being keeping the MutableState
object as an implementation detail. Then all of the usual OO patterns apply, the only difference is that changes to `ServiceX`'s internal state are observable.Noé Casas
01/20/2021, 3:55 PMwhateverString
by means of a public function of ServiceX
would trigger the repaint of Composables that use whateverString
(e.g. Text(serviceX.whateverString)
), right?Adam Powell
01/20/2021, 3:57 PMNoé Casas
01/20/2021, 3:57 PM