types(Graph, Cell, Element, Link): add JSON and BaseJSON types #2850
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Defines the type of the JSON generated by
graph.toJSON()
and the type of JSON accepted bygraph.fromJSON()
. Does so by definingElement.JSON
andLink.JSON
types to complement existingCell.JSON
type, and by defining a new typeCell.BaseJSON
(and correspondingElement.BaseJSON
andLink.BaseJSON
) which omits theid
argument.This is relevant for the
graph.fromJSON()
method, which accepts an array ofCell.BaseJSON
rather thanCell.JSON
- it can generate anid
for any cells that miss it. This has the practical effect that creators of synthetic graphs do not need to come up with IDs for their graph cells, and JointJS generates them for them usingcell.generateId()
method behind the scenes.On the other hand, the
graph.toJSON()
method is defined as using theCell.JSON
type since it always returns cells with IDs. The reason is that these cells come from a real graph object where all IDs have certainly been generated already.Additionally, splits
Link.EndJSON
into an OR statement of the signature with end cell ID or end point position, becauseLink.EndJSON
requires exactly one of these sets of arguments to be present (but not both or neither).