https://kotlinlang.org logo
#compose
Title
# compose
a

Andrey Kulikov

04/15/2020, 8:04 PM
we forgot to mention in the release notes but dev09 also contains new artifact
ui-livedata
and
ui-rxjava2
with adapters for these streams (see commits: livedata, rx). we also hope to provide an adapter for
Flow
soon
👍 1
🙏 9
z

Zach Klippenstein (he/him) [MOD]

04/15/2020, 8:17 PM
Why go through the indirection of returning a
State
, instead of just returning the value directly? Is it cheaper to “observe” a single model instance’s property multiple times than run this subscription/observation wiring multiple times?
I’m guessing the former involves fewer (no?) extra allocations?
a

Andrey Kulikov

04/15/2020, 9:01 PM
Returning raw values causes a frame read to happen as part of returning the value from the subscription function, causing the surrounding scope to recompose for value changes. By returning the underlying State<T> instead we can limit the scope of recompositions while sharing the subscription to different parts of the composition subtree. Plus this state can be used in draw or layout lamdas allowing us to skip recomposition and one redraw when the new value emitted. The syntax is the same as with a regular
state { }
, and similarly to it property delegation using
by
makes it easy to simplify the basic usages
z

Zach Klippenstein (he/him) [MOD]

04/15/2020, 10:37 PM
Cool, thanks for the explanation!
2 Views