Skip to content

feat: Add Router.isEmpty getter - #75

Merged
nielsenko merged 4 commits into
mainfrom
router-is-empty
May 21, 2025
Merged

nielsenko merged 4 commits into
mainfrom
router-is-empty

Conversation

@nielsenko

@nielsenko nielsenko commented May 19, 2025 •

Copy link
Copy Markdown
Collaborator

Description

  • New Feature:
    • Added isEmpty getter to Router (lib/src/router/router.dart) to indicate if any routes have been added.
    • Added isEmpty getter to _TrieNode and PathTrie (lib/src/router/path_trie.dart) to indicate if the trie contains any routes.
  • Refactoring:
    • Moved the LookupResult class from lib/src/router/path_trie.dart to a new file lib/src/router/lookup_result.dart
  • Exports:
    • Exported LookupResult from the main library file lib/relic.dart.

Related Issues

  • Closes: ?

Pre-Launch Checklist

Please ensure that your PR meets the following requirements before submitting:

  • This update focuses on a single feature or bug fix. (For multiple fixes, please submit separate PRs.)
  • I have read and followed the Dart Style Guide and formatted the code using dart format.
  • I have referenced at least one issue this PR fixes or is related to.
  • I have updated/added relevant documentation (doc comments with ///), ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully.
  • I have documented any breaking changes below.

Breaking Changes

  • Includes breaking changes.
  • No breaking changes.

Summary by CodeRabbit

  • New Features
    • Introduced the LookupResult<T> class to represent the outcome of route lookups, now available in the public API.
    • Added an isEmpty property to both PathTrie and Router classes, allowing users to check if any routes are registered.
  • Tests
    • Added tests to verify the behavior of the new isEmpty property in routers.

@coderabbitai

coderabbitai Bot commented May 19, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes introduce a new LookupResult<T> class in its own file and export it through the main library. The PathTrie and Router classes gain an isEmpty getter to indicate if any routes are registered. Associated tests are added to verify the new isEmpty property in the router.

Changes

File(s) Change Summary
lib/relic.dart Added export for src/router/lookup_result.dart to expose LookupResult in the public API.
lib/src/router/lookup_result.dart Introduced new LookupResult<T> class representing route lookup results.
lib/src/router/path_trie.dart Removed LookupResult definition, imported it from new file; added isEmpty getter to trie class.
lib/src/router/router.dart Added isEmpty getter to Router<T> to report if any routes are registered.
test/router/router_test.dart Updated imports; added tests for the new isEmpty property on the router.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant Router
    participant PathTrie

    Test->>Router: create Router<T>()
    Test->>Router: check isEmpty
    Router->>PathTrie: check isEmpty
    PathTrie-->>Router: return true
    Router-->>Test: return true

    Test->>Router: add route
    Test->>Router: check isEmpty
    Router->>PathTrie: check isEmpty
    PathTrie-->>Router: return false
    Router-->>Test: return false
Loading

Possibly related PRs

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5565aa7 and 5cf1cfe.

📒 Files selected for processing (5)
  • lib/relic.dart (1 hunks)
  • lib/src/router/lookup_result.dart (1 hunks)
  • lib/src/router/path_trie.dart (3 hunks)
  • lib/src/router/router.dart (2 hunks)
  • test/router/router_test.dart (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run Unit Tests (macos-latest, 3.3.0, upgrade)
  • GitHub Check: Run Unit Tests (macos-latest, 3.3.0, downgrade)
🔇 Additional comments (10)
lib/relic.dart (1)

24-24: Good addition of LookupResult export.

The export statement makes the newly separated LookupResult class accessible through the main library, which is essential for its public use after the refactoring.

lib/src/router/router.dart (2)

3-3: LGTM: Updated import for the refactored LookupResult class.

The import correctly references the new dedicated file for the LookupResult class that was moved from path_trie.dart.


129-130: Good addition of the isEmpty property.

This getter provides a convenient way to check if any routes have been registered without needing to look at the underlying implementation details. The method is well-documented and delegates to the corresponding property in the _allRoutes trie.

test/router/router_test.dart (3)

1-1: LGTM: Updated import for the refactored LookupResult class.

The import correctly references the new location of the LookupResult class.


23-25: Good test for isEmpty on a new router.

This test verifies that a newly created router correctly reports that it is empty.


56-61: Good test for isEmpty after adding a route.

This test correctly verifies that the isEmpty property returns false after a route has been added, ensuring the property behaves as expected.

lib/src/router/lookup_result.dart (1)

1-23: Well-structured LookupResult class with good documentation.

The LookupResult class has been effectively moved to its own file with:

  1. Clear imports
  2. Well-documented fields and class purpose
  3. Clean implementation

This refactoring improves the modularity of the codebase by separating concerns and making the class structure clearer.

lib/src/router/path_trie.dart (3)

1-1: Clean import update for relocated LookupResult class.

The import statement has been correctly updated to reference the newly dedicated file for the LookupResult class. This is a good refactoring decision that improves code organization and modularity.


19-21: Well-implemented isEmpty getter for _TrieNode.

The implementation correctly checks all three conditions that would make a node empty: no children, no dynamic segment, and no value. This provides a clear and comprehensive definition of emptiness for a trie node.


354-355: Good addition of isEmpty getter to PathTrie.

The isEmpty getter elegantly delegates to the root node's implementation, maintaining consistency and reusing code. This is a useful addition that allows clients to check if the trie contains any routes.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nielsenko nielsenko self-assigned this May 19, 2025
@codecov

codecov Bot commented May 19, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.35%. Comparing base (5565aa7) to head (5cf1cfe).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #75      +/-   ##
==========================================
+ Coverage   81.32%   81.35%   +0.03%     
==========================================
  Files          79       80       +1     
  Lines        2426     2430       +4     
  Branches     1361     1364       +3     
==========================================
+ Hits         1973     1977       +4     
  Misses        453      453              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 19, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nielsenko
nielsenko requested a review from SandPod May 20, 2025 06:37
@nielsenko
nielsenko marked this pull request as ready for review May 21, 2025 11:48

@SandPod SandPod 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.

🚀

@nielsenko
nielsenko merged commit 1730a54 into main May 21, 2025
@nielsenko
nielsenko deleted the router-is-empty branch May 21, 2025 11:55
@coderabbitai coderabbitai Bot mentioned this pull request Sep 17, 2025
6 of 9 tasks
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