Skip to content

refactor: increase usage of the MouseListenerSet interface#848

Merged
tbouffard merged 1 commit intomainfrom
refactor/more_usage_of_MouseListenerSet_interface
Jun 12, 2025
Merged

refactor: increase usage of the MouseListenerSet interface#848
tbouffard merged 1 commit intomainfrom
refactor/more_usage_of_MouseListenerSet_interface

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Jun 12, 2025

Changes:

  • This interface enforces the signature of “mouse” methods and makes it explicit that classes are listeners and can be added as such to Graph instances
  • It prevents “mouse” methods from being detected as unused by the IDE
  • Various enhancements have been made to JSDoc, in particular with regard to events launched by classes.

Summary by CodeRabbit

  • Documentation

    • Improved clarity and formatting of documentation comments across multiple components, including more detailed event descriptions, clearer parameter explanations, and updated code examples.
    • Standardized comment styles and corrected minor typos for better readability.
  • Refactor

    • Updated several class and method signatures to indicate unused parameters for improved code clarity.
    • Implemented interface updates for certain handler classes to ensure consistency and maintainability.

Changes:
  - This interface enforces the signature of “mouse” methods and makes it explicit that classes are listeners and can be added as such to Graph instances
  - It prevents “mouse” methods from being detected as unused by the IDE
  - Various enhancements have been made to JSDoc, in particular with regard to events launched by classes.
@tbouffard tbouffard added the refactor Code refactoring label Jun 12, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 12, 2025

Walkthrough

This change primarily updates documentation comments, refines example code formatting, and clarifies parameter usage across several core files. It also explicitly implements the MouseListenerSet interface for the PanningHandler, PopupMenuHandler, and SelectionHandler classes, and updates mouse event handler signatures to mark unused parameters. No functional or behavioral changes are introduced.

Changes

Files/Groups Change Summary
packages/core/src/gui/MaxPopupMenu.ts Improved documentation comments, reformatted JSDoc, and clarified event references for MaxPopupMenu and its methods.
packages/core/src/view/GraphView.ts Reformatted comment and replaced empty mouse event listener functions with comments.
packages/core/src/view/cell/CellMarker.ts Refined class-level documentation, updated event section, and improved example code formatting.
packages/core/src/view/cell/CellTracker.ts Updated example code in docs for modern syntax; replaced return; with comment in mouseUp.
packages/core/src/view/event/InternalMouseEvent.ts Reformatted example code in class documentation for concise arrow function style.
packages/core/src/view/mixins/EventsMixin.type.ts Corrected parameter types and improved descriptions in documentation comments.
packages/core/src/view/other/PanningManager.ts Replaced return statements with comments in mouse event handlers; minor doc wording fix.
packages/core/src/view/plugins/PanningHandler.ts Now implements MouseListenerSet; updated JSDoc; renamed unused parameters in event handlers for clarity.
packages/core/src/view/plugins/PopupMenuHandler.ts Now implements MouseListenerSet; renamed unused parameters in mouse event handler signatures; fixed minor comment typo.
packages/core/src/view/plugins/SelectionHandler.ts Now implements MouseListenerSet; updated method signatures to mark unused parameters; improved and reformatted JSDoc.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Graph
    participant MouseListenerSet
    participant PanningHandler
    participant PopupMenuHandler
    participant SelectionHandler

    User->>Graph: Triggers mouse event
    Graph->>MouseListenerSet: Dispatches event to listeners
    MouseListenerSet->>PanningHandler: Calls mouseDown/mouseMove/mouseUp(_sender, event)
    MouseListenerSet->>PopupMenuHandler: Calls mouseDown/mouseMove/mouseUp(_sender, event)
    MouseListenerSet->>SelectionHandler: Calls mouseDown/mouseMove/mouseUp(_sender, event)
Loading

Possibly related PRs

Suggested labels

documentation

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-12T14_51_08_730Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (2)
packages/core/src/view/plugins/PanningHandler.ts (1)

234-236: ⚠️ Potential issue

isActive condition is wrong – handler is always “active”

initialScale is numeric (default 0). The current check against null is never false, so isActive() always returns true.

-  return this.active || this.initialScale !== null;
+  return this.active || this.initialScale !== 0;

Correcting this restores the intended semantics (true only while panning or pinch-zooming).

packages/core/src/view/cell/CellTracker.ts (1)

90-96: 🛠️ Refactor suggestion

Align method signature with MouseListenerSet

MouseListenerSet.mouseDown expects (sender: EventSource, me: InternalMouseEvent).
Keeping the parameters (prefixed with _ to mark them unused) avoids accidental breakage if stricter compiler flags (--strictFunctionTypes) are enabled later.

-  mouseDown() {
-    return;
-  }
+  mouseDown(_sender: EventSource, _me: InternalMouseEvent): void {
+    // intentionally left blank
+  }
🧹 Nitpick comments (2)
packages/core/src/view/plugins/PopupMenuHandler.ts (1)

47-50: Nit – prefix unused parameter in gestureHandler for lint consistency

- this.gestureHandler = (sender: EventSource, eo: EventObject) => {
+ this.gestureHandler = (_sender: EventSource, eo: EventObject) => {

All other handlers use the underscore pattern; aligning this one avoids a stray unused-var warning.

packages/core/src/gui/MaxPopupMenu.ts (1)

171-184: Nit: unify optional-parameter notation in JSDoc

The new parameter list is clearer, but you could leverage JSDoc’s square-bracket notation for optional parameters to make it machine-parsable by more tooling:

- * @param image Optional URL for the image icon.
+ * @param [image] URL for the image icon.

(Same for the remaining optional params.)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2f79cd8 and 3f45abe.

📒 Files selected for processing (10)
  • packages/core/src/gui/MaxPopupMenu.ts (2 hunks)
  • packages/core/src/view/GraphView.ts (1 hunks)
  • packages/core/src/view/cell/CellMarker.ts (1 hunks)
  • packages/core/src/view/cell/CellTracker.ts (2 hunks)
  • packages/core/src/view/event/InternalMouseEvent.ts (1 hunks)
  • packages/core/src/view/mixins/EventsMixin.type.ts (1 hunks)
  • packages/core/src/view/other/PanningManager.ts (2 hunks)
  • packages/core/src/view/plugins/PanningHandler.ts (8 hunks)
  • packages/core/src/view/plugins/PopupMenuHandler.ts (5 hunks)
  • packages/core/src/view/plugins/SelectionHandler.ts (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/core/src/view/plugins/PopupMenuHandler.ts (2)
packages/core/src/types.ts (2)
  • GraphPlugin (1178-1180)
  • MouseListenerSet (1210-1214)
packages/core/src/util/EventUtils.ts (1)
  • isMultiTouchEvent (93-102)
packages/core/src/view/plugins/SelectionHandler.ts (1)
packages/core/src/types.ts (2)
  • GraphPlugin (1178-1180)
  • MouseListenerSet (1210-1214)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-22.04)
  • GitHub Check: build (macos-14)
  • GitHub Check: build
🔇 Additional comments (8)
packages/core/src/view/event/InternalMouseEvent.ts (1)

35-44: Documentation update looks good

The switch to concise arrow-function examples and consistent parameter naming improves readability without touching runtime behaviour.

packages/core/src/view/cell/CellMarker.ts (1)

41-58: Clearer JSDoc – nice polish

The refined example and “### Events” section bring the docs in line with the rest of the codebase. No functional impact detected.

packages/core/src/view/plugins/PopupMenuHandler.ts (1)

25-38: Interface declaration matches actual capabilities

Implementing MouseListenerSet (and importing it with type) provides compile-time guarantees and silences IDE “unused” warnings. Implementation already fulfils the contract.

packages/core/src/view/plugins/PanningHandler.ts (1)

34-70: Type-level conformance achieved

Adding MouseListenerSet keeps IDEs honest; type-only import prevents runtime overhead.

packages/core/src/view/plugins/SelectionHandler.ts (1)

527-545: Explicitly marking unused parameter

Renaming evtName_evtName cleanly suppresses the unused-parameter lint and mirrors other handlers.

packages/core/src/view/mixins/EventsMixin.type.ts (2)

226-233: Correct and consistent doc-comment update – looks good

The parameter reference was corrected to InternalMouseEvent, and the surrounding prose became clearer. No issues spotted.


235-238: Back-ticked method names clarify the interface – nice touch

Using back-ticks around mouseDown, mouseMove, and mouseUp prevents IDE mis-parsing and improves the generated docs.

packages/core/src/gui/MaxPopupMenu.ts (1)

47-54: Event section re-formatting is an improvement

Explicitly calling out InternalEvent.SHOW in its own “Events” section makes the docs easier to scan.

@tbouffard
Copy link
Member Author

ℹ️ The error detected by SonarCloud is not related to the changes provided in this PR.
It detects large cognitive complexity in SelectionHandler.

@tbouffard tbouffard merged commit 722b2ed into main Jun 12, 2025
6 of 7 checks passed
@tbouffard tbouffard deleted the refactor/more_usage_of_MouseListenerSet_interface branch June 12, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant