Skip to content

Refactor Perimeter and EdgeStyle to support tree shaking #759

@tbouffard

Description

@tbouffard

Is your feature request related to a problem? Please describe

It's currently not possible to import only a subset of the available Perimeter and EdgeStyle functions into a consuming application.
This results in larger bundle sizes, as all implementations are pulled in automatically.

Why? Because:

  • EdgeStyle is a class with static properties.
  • Perimeter is a value object (before v0.7.0, it was also a class with static methods, like EdgeStyle).

As soon as you import one, you get the whole thing.

Notice that having a class with only static properties are generally considered as a bad practice:

Describe the solution you'd like

We’d like to make these utilities tree-shakable.
Proposal:

  • Refactor EdgeStyle and Perimeter into a namespace.
    • This should allow tree shaking to work.
    • No impact for most consumers.
    • Might affect users who extended these objects (which is not recommended anyway).

Bonus tasks:

  • Move the JSDoc from the source code to the official documentation site.
  • Optionally: enable the ESLint unicorn/no-static-only-class rule to avoid to reintroduce class with only static properties.

Describe alternatives you've considered

  • Keeping the current implementation, but the size impact can be significant in consumer apps.
  • Splitting each function into its own file, but this would increase boilerplate and isn't as ergonomic.

Additional context

This refactoring would:

  • Help reduce the bundle size of apps using maxGraph.
  • Improve overall modularity and modern compatibility (e.g., ESM, tree shaking).
  • Be consistent with ongoing efforts to optimize for modern JS tooling.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions