# compose

Antanas A.

05/23/2019, 2:15 PM
Hi, I'm curious about design decisions between Compose and Scala.Binding ( ) and why Compose wasn't designed towards Scala.Binding, but went to kind of "virtual DOM" way.


05/23/2019, 2:17 PM
There is no any kind "virtual DOM" in Compose
You can check implementation details in article

Antanas A.

05/23/2019, 2:23 PM
so when it feels like mechanism is the same as scala.binding
Copy code
Unlike ReactJS, a Binding.scala @dom method is NOT a regular function. It is a template that describes the relationship between data source and the DOM. When part of the data source changes, Binding.scala knows about the exact corresponding partial DOM affected by the change, thus only re-evaluating that part of the @dom method to reflect the change in the DOM.
So the Compose is some kind of reactive model to AST tree transformer
but does it emit transformation instructions of AST?
or how exactly GUI rendering pipeline knows what to rerender
or these lightweight @Composable functions - nodes is bound to some kind of lambda callback functions "factory" and/or "update" which gets called when needed


05/23/2019, 3:47 PM
See the blog post a couple of comments up: for some details of the inner workings.

Leland Richardson [G]

05/23/2019, 4:49 PM
@Antanas A. if you’re asking how compose can know how to “recompose” just part of the composition hierarchy, you’re right that i did not attempt to cover that in the article 🙂 It was getting long as is, and didn’t want to throw another wrench into it. Compose works similar to how you suggest. There are parts of the tree we call “recompose scopes” which can be thought of as parameterless lambdas and a “starting position” of the backing memoization cache (which we call SlotTable). With this information, you can start at a point in the middle of the tree.
👍 1

Chuck Jazdzewski [G]

05/23/2019, 4:53 PM
function is transform function from its parameters to a mutable tree. In Compose the tree represents the UI of an application. The tree is responsible for tracking when it is modified as a result of composition to track when and where the screen should be updated.

Antanas A.

05/23/2019, 5:09 PM
thanks for responses
but how exactly rendering engine binds to that tree? Are there some observables which can be listened to? Or it returns a stream of changes? Im trying to imagine how different graphic engines will consume that tree

Ryan Mentley

05/24/2019, 3:28 AM
Basically it walks down the tree and calls the draw nodes