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

Julius Marozas

07/14/2020, 3:59 PM
I've been reading the source code of Compose and found that in the
rxjava2
package the
subscribeAsState
function calls
asState
and it uses the
onPreCommit
hook. Why would the
onCommit
hook not work there? I don't really understand the use case of
onPreCommit
.
a

Adam Powell

07/14/2020, 4:49 PM
The distinction is probably going away soon. The difference is that
onCommit
posts the event to happen "a bit later" rather than as we're actually applying the changes to the composition. The direction we're leaning in is that the current deferred
onCommit
behavior will go away and only the
onPreCommit
behavior will remain.
👍🏼 1
so the reason this is using
onPreCommit
is just a minor latency and timing improvement over
onCommit
.
j

Julius Marozas

07/14/2020, 5:09 PM
Oh, okay. So the reason they were made separate was not to overwhelm compose with not as crucial events (and put those in
onCommit
)?
a

Adam Powell

07/14/2020, 6:08 PM
no, the reason they were made separate is partially historical and had to do with whether it was risky or not to execute side effects of a composition while the process of applying them was still in progress, vs. after all of them have been completely applied.
Some internal dispatching logic around this changed and the
onPreCommit
path is already "deferred" until after all tree changes happen, but it doesn't yield to a system handler/scheduler to do it, which avoids ordering questions and a small amount of latency.
j

Julius Marozas

07/14/2020, 6:36 PM
Thanks for the detailed response!
👍 1