PartialTraversal

Summary:
Cleanup documentation as with the other traversal, no raw loops.

Note: about no raw loops philosophy

To make clear and explicit the intention of the code, in this case to iterate over all elements of a collection.

A raw loop exposes unwanted flexibility which makes it hard to reason about code. A raw loop body thus have control over the lifetime of the loop itself.
- continue
- break
- return

None of those can be used with a forEach for example. Thus we make it clear the intention of the code.

Reviewed By: LukeDefeo

Differential Revision: D39652960

fbshipit-source-id: ac660dc43256e7850bd18e31b00aa123783d5c98
This commit is contained in:
Lorenzo Blasa
2022-09-26 05:00:36 -07:00
committed by Facebook GitHub Bot
parent dfdeffbc09
commit 48f70ef8ec

View File

@@ -17,8 +17,9 @@ import com.facebook.flipper.plugins.uidebugger.model.Node
/**
* This will traverse the layout hierarchy until it sees a node that has an observer registered for
* it. The first item in the pair is the visited nodes The second item are any observable roots
* discovered
* it.
* - The first item in the pair is the visited nodes.
* - The second item are any observable roots discovered.
*/
class PartialLayoutTraversal(
private val descriptorRegister: DescriptorRegister,
@@ -32,11 +33,11 @@ class PartialLayoutTraversal(
val visited = mutableListOf<Node>()
val observableRoots = mutableListOf<Any>()
val stack = mutableListOf<Any>()
stack.add(root)
while (stack.isNotEmpty()) {
val node = stack.removeLast()
try {
@@ -49,11 +50,10 @@ class PartialLayoutTraversal(
val descriptor = descriptorRegister.descriptorForClassUnsafe(node::class.java).asAny()
val children = descriptor.getChildren(node)
val childrenIds = mutableListOf<Id>()
val activeChild = descriptor.getActiveChild(node)
for (child in children) {
val childrenIds = mutableListOf<Id>()
children.forEach { child ->
// It might make sense one day to remove id from the descriptor since its always the
// hash code
val childDescriptor =