Discussion regarding the proposed additional GraphInstantiators argument #151
Replies: 1 comment 4 replies
-
|
When I introduced To use a custom PanningHandler, for example, one can create a new PanningHandler(extended or brand new) class with the Honestly, I haven't tested much other than the few examples that override *Handler classes, and didn't change non-handler classes(ex. CellRenderer) to this structure, but I think it's doable. Let me know what you guys think :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As at #150, some of the original examples of mxGraph made changes to the
GraphDataModel,CellRenderer,ConnectionHandler,GraphViewin-place. In this (draft) branch, I proposed that an additional argument and type be introduced to the mainGraphconstructor to allow having changes to behavior in these classes while not needing to make global changes which affect all future classes of that type.@tbouffard raised that this approach may be inconsistent with what has been done previously:
I've actually been leaning more towards create* factory functions at times, as that has been what's been used for some but not all constructor calls in mxGraph in the base Graph class, but wasn't sure whether should adopt this pattern or reuse the pattern used for the plugins argument.
I suspect the plugins argument is mainly there for tree-shaking purposes. If the create* factory functions would be preferred, I would be inclined to alter this PR to do this, as don't have strong preferences between these approaches.
I believe the fundamental problem is the way certain methods in the original Graph class instantiate hardcoded references to those classes, in particular in the middle of reasonably complex logic such as in
Graph.createEdgeHandler. The original mxGraph prioritised inheritance over composition in many places, and it's made making changes like this which are not global tricky.The options as I see them are:
create*factory functions in the Graph object which can be overridenThe "alternative constructors to subclass as attributes" and "
create*factory functions" options seem to both be used reasonably frequently throughout the mxGraph codebase, and the alternative constructor provided to the constructor used only occasionally.What's everyone's thoughts on this? Are there any alternative approaches which I have missed?
Beta Was this translation helpful? Give feedback.
All reactions