Hi. For educational and no real good reason I want...
# compose
e
Hi. For educational and no real good reason I want to try implementing my own state handling in compose. It relies on observables. I'm struggling to see how the whole compose and recompose can be implemented this way. Something like
Copy code
Column {
  On("someting") {
    Text("Updated $it!")
  }
}
is what I'm aiming for
a
What is
On("something")
?
e
It's an observable with a callback. Very old-fashioned. Point is that when something changes, the Text should be recomposed
a
Then this is not how compose works. 🙂 Composable functions are declarative; they define what is in your UI, not what happens to it. An event like
On("something")
happens instantaneously and is done. You can instead set a state variable when this event happens and show this text using something like
if (myCondition)
e
I'm aware, but Compose also supports both RxJava and Flow (StateFlow), which is basically what I have. Except from where/how it's declared
In my tests I've been able to duplicate the Rx solution by copying their implementation. It works, but I would much prefer to control the recompose by using the
On
at a specific location. I've been digging in the Compose code and see it uses some cache to determine location of elements based on when the function block is called. It seems a bit hackish, but I haven't been able to hook into this and trigger a recompose
Just to be clear, the
On
would accept a function block, just like normal Compose UI elements, and this block will be called when the "something" changes
a
The
collectAsState
function and friends work the way they do for the same reasons coroutines return a value instead of passing them to a callback
e
Yes, so it is the same as my stuff. But in addition I would like to control recompose by location, instead of by where it is used. The whole recompose by usage is really magical to me