I've been digging at compose internals and was res...
# compose
v
I've been digging at compose internals and was researching Snapshots. I came across
GlobalSnapshotManager
which calls
Snapshot.registerGlobalWriteObserver
, which then calls
Snapshot.sendApplyNotifications()
on the Main dispatcher. This seems to make sense as writes to the global snapshot don't generate apply notifications, but what bothers me is that there's a few other places where
Snapshot.sendApplyNotifications
is called as well: for example in Recomposer.kt, WindowInsets.android.kt, SubComposeLayout.kt and ComposeViewAdapter.kt. Why are the explicit calls there required? Wouldn't all possible State writes eventually call apply observers when either 1) applying the snapshot to the global snapshot, or 2) triggering the global write observer?
Zach has an excellent writeup of the Snapshot system here https://dev.to/zachklipp/introduction-to-the-compose-snapshot-system-19cn, but it still remains a bit unclear to me how it's actually hooked up to the compose UI parts 🤔
s
Docs for
sendApplyNotifications
say “This method is implicitly called whenever a non-nested MutableSnapshot is applied making its changes visible to all new, non-nested snapshots.“. Could it be that for some scenarios you are actually in the “nested MutableSnapshot” scenario, so it’s not auto-applied? Maybe WindowInsets does that for example, takes a nested snapshot, does its thing, and then calls sendApplyNotifications?
v
I'm not really sure what "implicitly called" means in this case. The method itself is not called when applying snapshots: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]untime/snapshots/Snapshot.kt;l=709?q=sendApplyNotifications(), the apply method iterates through the observers manually and calls them