Controller which makes sure EventHandler instances are bound to the latest instance of the Component/Section that created them.

To see the problem this is trying to solve, consider a Section with a button Component with a click handler as one of its rows. When the section updates (e.g. performs a state update), nothing about how the button renders changes, so we don't want to re-resolve it. However, if we don't re-resolve it, the click handler points to an old instance of the Section (the Section before the state update).

To get the best of both worlds, we don't re-render the button and use this class to update the EventDispatchInfo on all EventHandlers created in this tree to their latest Component/Section owners.

In order to do this, all EventHandlers created by a given component/section (identified by their global key) is given a reference to the same EventDispatchInfo instance. Then on each tree resolution, we update this EventDispatchInfo with the latest instance of the context and component/section.

Details of the full flow in the context of Components

    • During a resolve or layout (or resolve+layout), we record all Spec-generated EventHandlers in a list local to this computation.

    • When we create EventHandlers, we create them with the latest ComponentContext and EventDispatcher (the two together are what we call DispatchInfo) but don't update any existing committed EventHandlers.

    • The ResolveResult has just the EventHandlers from resolve, but the LayoutState (result of layout computation) has both the EventHandlers created in resolve and the EventHandlers created in layout

    • If we commit this LayoutState, we 'canonicalize' the DispatchInfos on the EventHandlers we created. This means we update the collected EventHandler's DispatchInfos to be the 'canonical' DispatchInfos we already have for that global key (if we don't have one, that DispatchInfo becomes the canonical DispatchInfo for that key)

    • Finally, we update the canonical DispatchInfos for each global key to the latest ComponentContext/EventDispatcher from the newly committed LayoutState.

By having all committed EventHandlers for a global key reference the same DispatchInfo, we can update them all at the same time when a new LayoutState is committed.


Link copied to clipboard


Link copied to clipboard


Link copied to clipboard

For a list of Pair(GlobalKey, EventHandler), updates the EventDispatchInfo on each EventHandler to be the canonical EventDispatchInfos for the corresponding global key. This means that from now on, when EventDispatchInfos are re-bound in .updateEventDispatchInfoForGlobalKey, these EventHandlers will also be updated.

Link copied to clipboard

If a global key doesn't appear in the current tree, remove its EventDispatchInfo from our book keeping.

Link copied to clipboard

Updates the EventDispatchInfo for this global key with the latest context and component/section. All EventHandlers created by this global key have the same EventDispatchInfo instance.