-
Notifications
You must be signed in to change notification settings - Fork 853
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
feat(dia.Cell): new toJSON options #2728
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ptyAttributes options
…method and objectDifference util function
MartinKanera
changed the title
feat: new toJSON options
feat(dia.Cell): new toJSON options
Jul 31, 2024
kumilingus
requested changes
Aug 1, 2024
kumilingus
approved these changes
Aug 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR includes changes to the
dia.Cell.toJSON()
, now accepting two new options.opt.ignoreDefaults
(default['attrs']
) - accepts an array of attribute names to be compared to the defaults, additionally setting this option tofalse
will result in returning all of the attributes without comparing them, while setting it totrue
results in a comparison of all the attributes with defaultsopt.ignoreEmptyAttributes
(defaultfalse
) - determines if the result should include empty attributesThese two options are also applicable to
dia.Graph.toJSON()
method.This PR also includes a new
util.objectDifference
function used to determine the difference between two provided objects.Documentation
https://docs.jointjs.com/api/dia/Cell/#tojson
toJSON()
Return a copy of the cell's attributes for JSON serialization. This can be used for persistance or serialization. Note that this method doesn't return a JSON string but rather an object that can be then serialized to JSON with
JSON.stringify()
.By default,
opt.ignoreDefaults
is set to['attrs']
. This setting ensures that only non-default attributes in the attrs object are returned, as it compares the attrs object to its defaults. To include all attributes ofdia.Cell
without filtering out defaults, setopt.ignoreDefaults
tofalse
. Alternatively, settingopt.ignoreDefaults
totrue
will compare all attributes to their defaults, returning only those that differ. You can also provide an array of strings foropt.ignoreDefaults
, specifying a list of attributes to compare against their defaults.Additionally,
opt.ignoreEmptyAttributes
defaults tofalse
, which may include empty objects in the JSON output. To exclude empty objects, setopt.ignoreEmptyAttributes
totrue
.https://docs.jointjs.com/api/dia/Graph/#tojson
toJSON()
This method accepts an optional
opt
object, theopt.cellAttributes
accepts same options as the dia.Cell.toJSON() method, which will impact the result of thetoJSON()
method.https://docs.jointjs.com/api/util/
objectDifference()
Return an object that represents the difference between
object
andbase
.