Skip to content

Conversation

tbouffard
Copy link
Member

@tbouffard tbouffard commented Apr 28, 2025

Previously, Perimeter was a value object. So, most bundlers included the whole object even if only some values was
used in the application (i.e. the only perimeters registered in StyleRegistry).
Notice that some bundlers, like Rollup, was able to only keep the values effectively used by the application.

Perimeter is no longer an object, but a namespace, so all bundlers should now able to only keep the perimeters really
used by the application.

BREAKING CHANGES: Perimeter has been changed from a value object to a namespace. This has minimal impact for most applications that only read perimeter values.
The only breaking change affects applications that modify Perimeter properties (add/update/remove values): this is no longer possible.
Instead, create your own perimeter implementation and register it.

Notes

Covers #759

Impact on application size

Note

JS examples use Webpack, TS examples use Vite (Vite/Rollup does better tree-shaking!)

  • the JS and TS examples doesn't cover the same use case
  • the size mentioned here is the one of the whole application in the JS examples and the one of the maxGraph chunk in the TS examples
Example 0.18.0 This PR
js-example 476.1 kB 475.92 kB
js-example-selected-features 423.45 kB 415.59 kB
js-example-without-default 347.86 kB 347.83 kB
ts-example 439.30 kB 439.15 kB
ts-example-selected-features 381.15 kB 381.14 kB
ts-example-without-default 330.38 kB 330.38 kB

Analysis

In the examples "without-default", this PR has no impact because Perimeter is not used, so it was already tree-shaked.

The PR has no impact on "ts-example-selected-features".
Vite uses rollup to bundle and it was already shrinking the unused properties of the Perimeter value object.
This has been confirmed on the rollup example of the https://github.com/maxGraph/maxGraph-integration-examples/ repository.

Here is what rollup bundled with the former implementation (when disabling minification to make the code readable):

const RectanglePerimeter=...
const EllipsePerimeter=...

const Perimeter = {
  /**
   * Describes a rectangular perimeter.
   */
  RectanglePerimeter,
  /**
   * Describes an elliptic perimeter.
   */
  EllipsePerimeter
};

Summary by CodeRabbit

  • Documentation
    • Added a "Breaking Changes" section to the changelog, highlighting updates to the Perimeter entity.
  • Refactor
    • Simplified how perimeter functions are exported, moving from a grouped object to individual named exports.
    • Updated export style for Perimeter to use a namespace export with improved documentation.
    • Adjusted import paths to align with the new export structure.
  • Chores
    • Increased the chunk size warning limit in the Vite configuration.

Previously, `Perimeter` was a value object. So, most bundlers included the whole object even if only some values was
used in the application (i.e. the only perimeters registered in StyleRegistry).
Notice that some bundlers, like Rollup, was able to only keep the values effectively used by the application.

`Perimeter` is no longer an object, but a namespace, so all bundlers should now able to only keep the perimeters really
used by the application.

BREAKING CHANGES: `Perimeter` has been changed from a value object to a namespace. This has minimal impact for most applications that only read perimeter values.
The only breaking change affects applications that modify Perimeter properties (add/update/remove values): this is no longer possible.
Instead, create your own perimeter implementation and register it.
@tbouffard tbouffard added the enhancement New feature or request label Apr 28, 2025
Copy link

coderabbitai bot commented Apr 28, 2025

Walkthrough

This set of changes refactors how the Perimeter functionality is exported and consumed within the codebase. The Perimeter entity is changed from a value object to a namespace, and its export statements are updated accordingly. Documentation is updated to reflect this breaking change, and internal imports are redirected to the new namespace export. Additionally, the Vite build configuration is slightly adjusted by increasing the chunk size warning limit.

Changes

File(s) Change Summary
CHANGELOG.md Added a "Breaking Changes" entry under "Unreleased" to document the Perimeter refactor from value object to namespace.
packages/core/src/view/style/builtin-style-elements.ts Changed export from named to namespace export for Perimeter; added JSDoc describing the namespace.
packages/core/src/view/style/perimeter/index.ts Refactored to remove the Perimeter object; now directly re-exports perimeter functions as named exports.
packages/core/src/view/style/register.ts Updated import of Perimeter to use the new namespace export from builtin-style-elements.
packages/ts-example-selected-features/vite.config.js Increased the chunkSizeWarningLimit from 369 to 382 in the Vite build configuration.

Sequence Diagram(s)

sequenceDiagram
    participant UserApp
    participant PerimeterNamespace
    participant PerimeterFunctions

    UserApp->>PerimeterNamespace: Import Perimeter as namespace
    PerimeterNamespace->>PerimeterFunctions: Expose RectanglePerimeter, EllipsePerimeter, etc.
    UserApp->>PerimeterNamespace: Use Perimeter.RectanglePerimeter (read-only)
Loading

Possibly related issues

Possibly related PRs

Suggested labels

refactor

✨ 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.
    • 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 @coderabbitai in 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 @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 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 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.

Copy link

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: 1

🧹 Nitpick comments (2)
CHANGELOG.md (1)

12-15: Ensure proper Markdown list indentation
The continuation line under the bullet should be indented by at least four spaces for consistency with CommonMark:

@@
- - `Perimeter` has been changed from a value object to a namespace. This has minimal impact for most applications that only read perimeter values.
-   The only breaking change affects applications that modify Perimeter properties (add/update/remove values): this is no longer possible. Instead, create your own perimeter implementation and register it.
+ - `Perimeter` has been changed from a value object to a namespace. This has minimal impact for most applications that only read perimeter values.
+     The only breaking change affects applications that modify Perimeter properties (add/update/remove values): this is no longer possible. Instead, create your own perimeter implementation and register it.
packages/core/src/view/style/builtin-style-elements.ts (1)

19-24: Add @SInCE tag to the Perimeter namespace JSDoc
Other namespace exports (e.g., EdgeMarker) include a @since tag; adding it here improves consistency and helps consumers track when this breaking change was introduced.

 /**
  * Provides various perimeter functions to be used in a style as the value of {@link CellStateStyle.perimeter}.
  *
+ * @since 0.18.0
  * @category Perimeter
  */
 export * as Perimeter from './perimeter';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 676dbd8 and d788968.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • packages/core/src/view/style/builtin-style-elements.ts (1 hunks)
  • packages/core/src/view/style/perimeter/index.ts (1 hunks)
  • packages/core/src/view/style/register.ts (1 hunks)
  • packages/ts-example-selected-features/vite.config.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (macos-14)
  • GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (2)
packages/ts-example-selected-features/vite.config.js (1)

30-30: Approve bump of chunkSizeWarningLimit
Raising the chunkSizeWarningLimit to 382 for the @maxgraph/core chunk aligns with the recent increase in bundle size and avoids superfluous warnings.

packages/core/src/view/style/perimeter/index.ts (1)

19-23: Tree-shaking is improved via direct named exports
Breaking out each perimeter function as its own named export eliminates the old aggregate object and ensures unused implementations are dropped by bundlers.

@tbouffard tbouffard marked this pull request as draft April 28, 2025 06:55
@tbouffard tbouffard marked this pull request as ready for review April 28, 2025 12:06
@tbouffard tbouffard merged commit 97ec7d0 into main Apr 28, 2025
7 checks passed
@tbouffard tbouffard deleted the feat/perimeter_tree-shaking branch April 28, 2025 12:07
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.

1 participant