feat!: improve tree-shaking by isolating SelectionCellsHandler dependencies by tbouffard · Pull Request #823 · maxGraph/maxGraph · GitHub
Skip to content

feat!: improve tree-shaking by isolating SelectionCellsHandler dependencies#823

Draft
tbouffard wants to merge 27 commits into
mainfrom
refactor/762-edgeHandler_factory_move_out_of_AbstractGraph
Draft

feat!: improve tree-shaking by isolating SelectionCellsHandler dependencies#823
tbouffard wants to merge 27 commits into
mainfrom
refactor/762-edgeHandler_factory_move_out_of_AbstractGraph

Conversation

@tbouffard

@tbouffard tbouffard commented May 9, 2025

Copy link
Copy Markdown
Member

Move handler creation logic from AbstractGraph to SelectionCellsHandler plugin where it's actually used.
This prevents automatic inclusion of VertexHandler and EdgeHandler classes (~83kB) when the plugin isn't being used (for example, in applications that perform Graph visualization only, without Cell section).

ADDED:

  • Support for registering additional edge handlers beyond the built-in ones

BREAKING CHANGES:

  • Removed AbstractGraph.createHandler methods, now in SelectionCellsHandler
  • Handler customization now uses composition instead of inheritance, by using
    configureVertexHandler() and configureEdgeHandler() instead of extending Graph

Notes

Covers #762

Impact on the size of the examples

Note: experiment in #449 had shown a potential decrease of 63-66 kB, here we see 83.5 kB!

1st measures (to be confirmed)
We see a decrease only on example "without defaults", others use the SelectionCellsHandler plugin

  • TS: 226.94 kB vs 309.40 kB --> 83.5 kb!
  • JS: 242.37 vs 325.79 kB --> 83.5 kb!

Additional measure: without subclasses of EdgeHandler

In the future (#890), we may provide a way to configure the EdgeHandler that are registered in the plugin to reduce the size of application that doesn't require them:

  • no children 7-8 kB
  • Elbow only: 5 kB
  • Segment only: 0 kB. Segment extends Elbow so it is imported as well.

Remaining Tasks

@tbouffard tbouffard added the enhancement New feature or request label May 9, 2025
@coderabbitai

coderabbitai Bot commented May 9, 2025

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

tbouffard added 23 commits July 31, 2025 16:57
…encies

Move handler creation logic from AbstractGraph to SelectionCellsHandler plugin
where it's actually used. This prevents automatic inclusion of VertexHandler
and EdgeHandler classes (~63kB) when the plugin isn't being used (for example,
in applications that perform Graph visualization only, without Cell section).

ADDED:
- Support for registering additional edge handlers beyond the built-in ones

BREAKING CHANGES:
- Removed AbstractGraph.createHandler methods, now in SelectionCellsHandler
- Handler customization now uses composition instead of inheritance, by using
  configureVertexHandler() and configureEdgeHandler() instead of extending Graph
@tbouffard tbouffard force-pushed the refactor/762-edgeHandler_factory_move_out_of_AbstractGraph branch from 12885b7 to e1b84d6 Compare July 31, 2025 15:36
EdgeStyleHandlerKind,
EdgeHandlerFactoryFunction
>([
['default', (state: CellState) => new EdgeHandler(state)],

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Type of parameter can be omit in the factory functions

import type AbstractCanvas2D from './view/canvas/AbstractCanvas2D.js';
import type Cell from './view/cell/Cell.js';
import type CellState from './view/cell/CellState.js';
import CellState from './view/cell/CellState.js';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nitpick: revert removal of the type directive.
We only manage types here!

@sonarqubecloud

sonarqubecloud Bot commented Aug 1, 2025

Copy link
Copy Markdown

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