Is there a way to trigger recomposition when a single property of an object changes in compose? I know remember { mutableStateOf(x) } won’t work as the object reference remains the same. I know this could be solved by using the .copy() method to update the property and the object reference, however, the property is only ever modified inside of the object (in a separate module), but needs to be read outside of it.
UI Code in question:
val sp = SharedState.state.processor.rememberSp()
...
Text("Stack pointer is $sp")
SharedState.state is a singleton object containing persistant objects for the program.
.processor is an instance of the Processor class, part of which is show below.
Processor class:
class Processor(...) {
val stackptr: UInt get() = stack.ptr //readonly property
private val stack = Stack(memory, stackRange.last - stackRange.first, stackRange.first) //internal class
@Composable inline fun rememberSp() = currentComposer.cache(currentComposer.changed(stackptr)) { stackptr } //tried
@Composable inline fun rememberSp2() = remember(stackptr) { stackptr } //tried
@Composable inline fun rememberSp3() = remember { mutableStateOf(stackptr) } //tried
...
}
none of these methods serve to allow ui recomposition of the stack.ptr property. Any help is appreciated.