Hi, could anyone explain how @Composable annotatio...
# compose
a
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
l
It's not returned. It passes a mutable tree (much like suspending functions pass a
CoroutineContext
, but also enables optimization like not refreshing what is known to not change.
a
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
CraneWrapper
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.
r
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
t
@romainguy that’s a sweet turnaround. It will rise speculations on cross-platform framework competing with flutter
👍 1
l
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
a
Thank you all for replies!