refactor: remove `isNotNullish` internal function by tbouffard · Pull Request #732 · maxGraph/maxGraph
Walkthrough
This PR removes the exported isNotNullish function from the utilities module and updates its usage across multiple files. Calls formerly using isNotNullish are now replaced with inverted checks using isNullish. These changes affect view-layer methods—including alternate text handling, attribute checking, shape transformation, and stroke width parsing. Minor improvements, such as updating variable declarations from var to const in one file, are also included.
Changes
| File(s) | Change Summary |
|---|---|
packages/core/.../Utils.ts |
Removed the exported isNotNullish function and its accompanying documentation. |
packages/core/.../[SvgCanvas2D.ts, Cell.ts, Shape.ts, StencilShape.ts] |
Updated import statements to replace isNotNullish with isNullish; modified conditions by inverting null checks (using !isNullish) in methods (e.g., getAlternateText, createAlternateContent, hasAttribute, cloneValue, shape transformation, stroke width parsing); also refined variable declarations in Cell.ts (from var to const). |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant SvgCanvas2D
Caller->>SvgCanvas2D: getAlternateText(str)
SvgCanvas2D->>SvgCanvas2D: Evaluate condition (!isNullish(str))
alt str is not nullish
SvgCanvas2D-->>Caller: Return foAltText
else str is nullish
SvgCanvas2D-->>Caller: Return default text (or undefined)
end
Possibly Related PRs
- refactor!: remove
Client.isBrowserSupported#679: Adjusts the public visibility ofisNullishandisNotNullish, directly relating to their removal and usage changes in this PR. - refactor!: mark
isNullishandisNotNullishas private #661: Modifies the accessibility of the nullish utility functions, aligning with the updated null checks introduced here. - refactor: improve
StencilShapeRegistrymethod signatures #660: Implements similar changes in theStencilShape.tsfile by replacingisNotNullishwith negatedisNullishchecks.
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
packages/core/src/util/Utils.ts(0 hunks)packages/core/src/view/canvas/SvgCanvas2D.ts(4 hunks)packages/core/src/view/cell/Cell.ts(5 hunks)packages/core/src/view/geometry/Shape.ts(2 hunks)packages/core/src/view/geometry/node/StencilShape.ts(2 hunks)
💤 Files with no reviewable changes (1)
- packages/core/src/util/Utils.ts
🧰 Additional context used
🧬 Code Definitions (4)
packages/core/src/view/geometry/Shape.ts (1)
packages/core/src/util/Utils.ts (1)
isNullish(60-61)
packages/core/src/view/canvas/SvgCanvas2D.ts (2)
packages/core/src/util/Utils.ts (1)
isNullish(60-61)packages/core/src/view/canvas/XmlCanvas2D.ts (1)
text(861-922)
packages/core/src/view/geometry/node/StencilShape.ts (1)
packages/core/src/util/Utils.ts (1)
isNullish(60-61)
packages/core/src/view/cell/Cell.ts (1)
packages/core/src/util/Utils.ts (1)
isNullish(60-61)
🔇 Additional comments (11)
packages/core/src/view/geometry/node/StencilShape.ts (2)
23-23: Import statement updated to remove redundant utility function.The import statement has been updated to use
isNullishinstead ofisNotNullish, aligning with the PR objective to remove the redundant utility function.
134-134: Logic correctly converted to use negatedisNullish.The code has been updated to use
!isNullish(sw)instead ofisNotNullish(sw)while maintaining the original behavior. This is a clean change that preserves the same conditional logic.packages/core/src/view/canvas/SvgCanvas2D.ts (3)
19-19: Import statement updated to remove redundant utility function.The import statement has been updated to use
isNullishinstead ofisNotNullish, aligning with the PR objective to remove the redundant utility function.
425-425: Logic correctly converted to use negatedisNullish.The code in the
getAlternateTextmethod has been updated to use!isNullish(str)instead ofisNotNullish(str)while maintaining the original behavior.
463-463: Logic correctly converted to use negatedisNullish.The code in the
createAlternateContentmethod has been updated to use!isNullish(text)instead ofisNotNullish(text)while maintaining the original behavior.packages/core/src/view/geometry/Shape.ts (2)
20-20: Import statement updated to remove redundant utility function.The import statement has been updated to use
isNullishinstead ofisNotNullish, aligning with the PR objective to remove the redundant utility function.
652-652: Logic correctly converted to use negatedisNullish.The code has been updated to use
!isNullish(c.state.transform)instead ofisNotNullish(c.state.transform)while maintaining the original behavior.packages/core/src/view/cell/Cell.ts (4)
24-24: Import statement updated to remove redundant utility function.The import statement has been updated to use
isNullishinstead ofisNotNullish, aligning with the PR objective to remove the redundant utility function.
38-60: Code style improvements with template literals.The code examples in the documentation comments have been updated to use consistent formatting and code style, which improves readability.
565-565: Logic correctly converted to use negatedisNullish.The code in the
hasAttributemethod has been updated to use!isNullish(userObject.getAttribute?.(name))instead ofisNotNullish(userObject.getAttribute?.(name))while maintaining the original behavior.
614-617: Logic correctly converted to use negatedisNullish.The code in the
cloneValuemethod has been updated to use!isNullish(value)and!isNullish(value.nodeType)instead of their respectiveisNotNullishcounterparts, while maintaining the original behavior.
✨ 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.
🪧 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.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin 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 generate unit testing code.@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.
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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai planto trigger planning for file edits and PR creation.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.