Francois Morvillier
03/18/2021, 2:14 PMAdam Powell
03/18/2021, 2:47 PMval result = remember { mutableStateOf(initialValue) }
Use a LaunchedEffect
or DisposableEffect
to manage a subscription to an external observable type
return result
Adam Powell
03/18/2021, 2:48 PMresult
to the new value of the external observable whenever it changes.Francois Morvillier
03/18/2021, 9:48 PMclass DataHolder: State<Graph> { // extend my current DataHolder in some way so that it works like a MutableState. Implementing State<Graph> would be ideal but I suppose it's not that simple
//...
}
@Composable
fun DataView(dataHolder: DataHolder) {
Text("graph size: ${dataHolder.graph.getSize()}")
}
// ...
graph.addNode(...) // notifies dataHolder and triggers recomposition
Adam Powell
03/18/2021, 10:06 PMclass Graph {
private val nodes = mutableStateListOf<Node>()
fun addNode(node: Node) {
nodes += node
}
fun getSize(): Int = nodes.size
}
the above class is observable to compose, since its internal mutable state is implemented using the SnapshotStateList
returned by mutableStateListOf
Adam Powell
03/18/2021, 10:08 PMState<T>
typeFrancois Morvillier
03/18/2021, 10:45 PMAdam Powell
03/19/2021, 12:28 AM