Shift fetching litho attributes to background thread

Summary: Due to litho component instances being immutable we are able to process them later if we hold on to the instance. We have added a Maybe deferred type which sort of resembles a Monad. It wraps a value which may or may not be calculated later.

Reviewed By: lblasa

Differential Revision: D41474251

fbshipit-source-id: 2ba6e688518dba55cf4aa5ba53f390a92cf0921f
This commit is contained in:
Luke De Feo
2022-11-23 03:45:26 -08:00
committed by Facebook GitHub Bot
parent c95c59342e
commit 7ec09b4f95
12 changed files with 109 additions and 45 deletions

View File

@@ -15,6 +15,8 @@ import com.facebook.flipper.plugins.uidebugger.litho.descriptors.props.LayoutPro
import com.facebook.flipper.plugins.uidebugger.model.Bounds
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
import com.facebook.flipper.plugins.uidebugger.model.MetadataId
import com.facebook.flipper.plugins.uidebugger.util.Deferred
import com.facebook.flipper.plugins.uidebugger.util.MaybeDeferred
import com.facebook.litho.DebugComponent
class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescriptor<DebugComponent> {
@@ -67,19 +69,20 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto
private val UserPropsId =
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "Litho Props")
override fun getData(node: DebugComponent): Map<MetadataId, InspectableObject> {
override fun getData(node: DebugComponent): MaybeDeferred<Map<MetadataId, InspectableObject>> {
return Deferred {
val attributeSections = mutableMapOf<MetadataId, InspectableObject>()
val attributeSections = mutableMapOf<MetadataId, InspectableObject>()
val layoutProps = LayoutPropExtractor.getProps(node)
attributeSections[LayoutId] = InspectableObject(layoutProps.toMap())
val layoutProps = LayoutPropExtractor.getProps(node)
attributeSections[LayoutId] = InspectableObject(layoutProps.toMap())
if (!node.canResolve()) {
val props = ComponentPropExtractor.getProps(node.component)
attributeSections[UserPropsId] = InspectableObject(props.toMap())
}
if (!node.canResolve()) {
val props = ComponentPropExtractor.getProps(node.component)
attributeSections[UserPropsId] = InspectableObject(props.toMap())
attributeSections
}
return attributeSections
}
override fun getBounds(node: DebugComponent): Bounds =