DEV Community

loading...

Discussion on: remember { mutableStateOf() } – A cheat sheet

Collapse
louiscad profile image
Louis CAD

If I make an interface of val properties, and implement it with a class that delegates these to a Compose State/MutableState, I'll not get the observability for Composable functions because, and the only way through is to expose State<T> instead of T, right?

Collapse
zachklipp profile image
Zach Klippenstein Author

Nope, that still works. Reads are tracked by actual calls to the getter of a State.value, no matter where or how it is called. Also, there’s no compiler magic here. I believe under the hood there is actually a thread local installed that points to the current snapshot and reads record themselves there. So it doesn’t matter what your call stack looks like.

Collapse
louiscad profile image
Louis CAD

Oh, that's very neat!
Thanks for the info. I hope this knowledge makes it into the official docs.