-
Notifications
You must be signed in to change notification settings - Fork 194
feat!: improve tree-shaking of Perimeter
#785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
WalkthroughThis set of changes refactors how the Changes
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)
Possibly related issues
Possibly related PRs
Suggested labels
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this 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
📒 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 thechunkSizeWarningLimit
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.
Previously,
Perimeter
was a value object. So, most bundlers included the whole object even if only some values wasused 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 reallyused 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!)
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):
Summary by CodeRabbit