# compose

Antanas A.

05/14/2019, 8:30 AM
Hi, could anyone explain how @Composable annotation works under the hood? Is it creates some kind of AST tree which is returned when calling annotated function? I'm thinking maybe this concept can be used generally for "Interpreter pattern" where any actions can be written as @Composable and when AST could be traversed and interpreted later.
👍 2


05/14/2019, 11:25 AM
It's not returned. It passes a mutable tree (much like suspending functions pass a
, but also enables optimization like not refreshing what is known to not change.

Antanas A.

05/14/2019, 12:00 PM
But passes to what? Or it's like coroutine builder but instead of CoroutineContext it creates RenderingContext
and on that context all @Composable functions make a mutations on that RenderingContext?
so by looking examples is
is like "coroutine builder"?
and are these @Composable functions is forms something like AST on that RenderingContext or they are immediately execute "rendering/drawing" instructions on that RenderingContext.


05/14/2019, 2:26 PM
The compose compiler and core runtime don't know anything about UI and could work on any tree
👌 4
You could make any tree like API reactive


05/14/2019, 2:53 PM
@romainguy that’s a sweet turnaround. It will rise speculations on cross-platform framework competing with flutter
👍 1

Leland Richardson [G]

05/14/2019, 4:03 PM
CraneWrapper is pretty unrelated to all of this. Louis is right that composable invocations appeal to a scope/context object that is threaded through the functions implicitly, very similar to how suspend functions work under the hood today. That context object is where we are able to do memoizations against the previous composition, keeping allocations down and mutating the existing tree instead of creating a new one. The design we are using to do this is fairly different from other declarative frameworks and is something we will be writing deeper dives into in the future.
👍 8

Antanas A.

05/15/2019, 7:07 AM
Thank you all for replies!