Home / Function/ getLowestCommonAncestor() — react Function Reference

getLowestCommonAncestor() — react Function Reference

Architecture documentation for the getLowestCommonAncestor() function in ResponderEventPlugin.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  260a6097_933c_f093_faae_ae88bfab0cce["getLowestCommonAncestor()"]
  674c6180_b91e_e17d_fb2d_40a6a3631bb3["ResponderEventPlugin.js"]
  260a6097_933c_f093_faae_ae88bfab0cce -->|defined in| 674c6180_b91e_e17d_fb2d_40a6a3631bb3
  732fb477_d858_94a9_efff_34067b22778c["setResponderAndExtractTransfer()"]
  732fb477_d858_94a9_efff_34067b22778c -->|calls| 260a6097_933c_f093_faae_ae88bfab0cce
  5150711c_d8bc_1881_a612_f2d9f4cd1d44["getParent()"]
  260a6097_933c_f093_faae_ae88bfab0cce -->|calls| 5150711c_d8bc_1881_a612_f2d9f4cd1d44
  style 260a6097_933c_f093_faae_ae88bfab0cce fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-native-renderer/src/legacy-events/ResponderEventPlugin.js lines 176–208

export function getLowestCommonAncestor(instA, instB) {
  let depthA = 0;
  for (let tempA = instA; tempA; tempA = getParent(tempA)) {
    depthA++;
  }
  let depthB = 0;
  for (let tempB = instB; tempB; tempB = getParent(tempB)) {
    depthB++;
  }

  // If A is deeper, crawl up.
  while (depthA - depthB > 0) {
    instA = getParent(instA);
    depthA--;
  }

  // If B is deeper, crawl up.
  while (depthB - depthA > 0) {
    instB = getParent(instB);
    depthB--;
  }

  // Walk in lockstep until we find a match.
  let depth = depthA;
  while (depth--) {
    if (instA === instB || instA === instB.alternate) {
      return instA;
    }
    instA = getParent(instA);
    instB = getParent(instB);
  }
  return null;
}

Domain

Subdomains

Calls

Frequently Asked Questions

What does getLowestCommonAncestor() do?
getLowestCommonAncestor() is a function in the react codebase, defined in packages/react-native-renderer/src/legacy-events/ResponderEventPlugin.js.
Where is getLowestCommonAncestor() defined?
getLowestCommonAncestor() is defined in packages/react-native-renderer/src/legacy-events/ResponderEventPlugin.js at line 176.
What does getLowestCommonAncestor() call?
getLowestCommonAncestor() calls 1 function(s): getParent.
What calls getLowestCommonAncestor()?
getLowestCommonAncestor() is called by 1 function(s): setResponderAndExtractTransfer.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free