Skip to content

feat: add public traverse() method to TreeView#506

Merged
willeastcott merged 1 commit into
mainfrom
feat/treeview-traverse
Feb 26, 2026
Merged

feat: add public traverse() method to TreeView#506
willeastcott merged 1 commit into
mainfrom
feat/treeview-traverse

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Summary

  • Adds a public traverse() method to TreeView that visits every TreeViewItem depth-first
  • Updates expandAll() and collapseAll() to use the new public method instead of the protected _traverseDepthFirst directly
  • Adds unit tests for traverse() covering both populated and empty trees

Details

The existing _traverseDepthFirst method is protected, forcing consumers (like the Editor) to build their own traversal. The new traverse() method delegates to it, providing a clean public API:

treeView.traverse((item: TreeViewItem) => {
    console.log(item.text);
});

Test plan

  • Full build passes including type generation (npm run build)
  • All existing tests pass (npm test)
  • Lint passes (npm run lint)
  • New unit tests verify depth-first order and empty tree edge case

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a public traverse() method to the TreeView component, providing a clean API for depth-first traversal of tree items. Previously, consumers needed to use the protected _traverseDepthFirst() method or implement their own traversal logic. The new method makes the common use case of visiting all tree items simpler and more discoverable.

Changes:

  • Added public traverse() method to TreeView with comprehensive JSDoc documentation
  • Refactored expandAll() and collapseAll() to use the new public method
  • Added unit tests verifying depth-first traversal order and empty tree handling

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/components/TreeView/index.ts Added public traverse() method wrapping the existing protected _traverseDepthFirst() method; updated expandAll() and collapseAll() to use the new public API
test/components/treeview.mjs Added test suite for traverse() covering depth-first order verification and empty tree edge case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@willeastcott willeastcott merged commit bd0e9bb into main Feb 26, 2026
9 checks passed
@willeastcott willeastcott deleted the feat/treeview-traverse branch February 26, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants