Attachable

interface Attachable

Interface for something (e.g. a Component or a useEffect registration) which should receive callbacks when it is attached/detached from the tree.

Properties

Link copied to clipboard
abstract val uniqueId: String

Functions

Link copied to clipboard
abstract fun attach()

Will be invoked when this Attachable becomes a committed part of the ComponentTree. E.g. for a Component, when that Component first appears as part of a committed layout.

Link copied to clipboard
abstract fun detach()

Will be invoked when this Attachable is no longer part of the ComponentTree. This can be because the ComponentTree is released (and all Attachables are detached), or because this Attachable no longer appears in the ComponentTree in the most recent committed layout.

Link copied to clipboard
abstract fun shouldUpdate(nextAttachable: Attachable): Boolean

Given an Attachable (nextAttachable) with the same unique id as this Attachable and which is in the next layout, return whether it should be attached instead of the current Attachable. If true is returned, this Attachable will be detached and nextAttachable will be attached. If false is returned, this Attachable will remain attached and nextAttachable will be thrown away.

Link copied to clipboard

Legacy update behavior is that if shouldUpdate(Attachable) returns false, we should still replace the Attachable with the latest version of the Attachable. Practically speaking, this is needed for Layout Specs and the OnAttached/OnDetached API where OnAttached can be called with the initial component props, but OnDetached is expected to be called with the latest Component props.