Skip to content

Refactor LayoutTree from class to functional API#16

Closed
mass2527 wants to merge 1 commit intomainfrom
claude/review-module-design-fVmA2
Closed

Refactor LayoutTree from class to functional API#16
mass2527 wants to merge 1 commit intomainfrom
claude/review-module-design-fVmA2

Conversation

@mass2527
Copy link
Copy Markdown
Owner

@mass2527 mass2527 commented Mar 5, 2026

Summary

Converted the LayoutTree class into a functional API with standalone exported functions, eliminating the need for class instantiation and simplifying the codebase.

Key Changes

  • Removed LayoutTree class: Replaced the class-based approach with functional exports (findNode, findParentNode, replaceChildNode)
  • Updated LayoutManager: Changed from storing a LayoutTree instance (_tree) to directly storing the root node (_root), passing it as a parameter to utility functions
  • Simplified function signatures: Functions now take the root node as an explicit parameter instead of accessing it via class state
  • Updated all call sites: Modified LayoutManager and test files to use the new functional API
  • Re-exported findParentNode: Made the existing utility function available as a public export from LayoutTree.ts

Implementation Details

  • The findNode and replaceChildNode functions now accept root: LayoutNode | null as their first parameter
  • The internal findNodeInSubTree helper remains private but is now a standalone function
  • All functionality is preserved; this is purely a structural refactoring from OOP to functional programming
  • Tests were updated to call functions directly instead of instantiating the class

https://claude.ai/code/session_01QFjTD3NY8jFj2Gm63KUREV

Replace LayoutTree class wrapper with standalone findNode, findParentNode,
and replaceChildNode functions. The class only held a root reference that
LayoutManager already owns, making it a shallow module with unnecessary
indirection. LayoutManager now owns root state directly and passes it to
tree utility functions.

https://claude.ai/code/session_01QFjTD3NY8jFj2Gm63KUREV
@mass2527 mass2527 force-pushed the claude/review-module-design-fVmA2 branch from e8391b6 to d29490e Compare March 5, 2026 13:46
@mass2527 mass2527 closed this Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants