-
Notifications
You must be signed in to change notification settings - Fork 199
docs: add a Codecs page #524
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
Conversation
8de3ec6 to
a7d55f8
Compare
WalkthroughThis pull request introduces significant updates to the documentation and implementation of the Changes
Sequence DiagramsequenceDiagram
participant Developer
participant CodecRegistry
participant Codec
participant GraphDataModel
Developer->>CodecRegistry: Register codecs
CodecRegistry-->>Developer: Codec registration confirmed
Developer->>Codec: Encode object
Codec->>GraphDataModel: Convert to XML
GraphDataModel-->>Codec: XML representation
Codec-->>Developer: Serialized XML
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Briefly explain what they do and how to configure them
[skip ci]
a7d55f8 to
847f29c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
packages/website/docs/usage/codecs.md (5)
16-16: Fix grammatical errorChange "lets maxGraph knows" to "lets maxGraph know" or "allows maxGraph to know".
21-21: Improve sentence clarityRephrase to: "To use codecs, you must register them for the classes you want to encode/decode before using a
Codec."🧰 Tools
🪛 LanguageTool
[grammar] ~21-~21: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...egistration The use of codecs requires to register the codecs for the classes you want to ...(ALLOW_TO)
88-88: Fix unclear sentence structureThe sentence is unclear and missing words. Suggested revision:
"maxGraph provides special support to importmxGraphmodels, which have a different XML structure"🧰 Tools
🪛 LanguageTool
[uncategorized] ~88-~88: Possible missing comma found.
Context: ...s a special support to importmxGraphmodels which you a different XML structure (ma...(AI_HYDRA_LEO_MISSING_COMMA)
[grammar] ~88-~88: A verb may be missing between “you” and “a”, or a word may be misspelled.
Context: ...upport to importmxGraphmodels which you a different XML structure (mainly because...(PRP_THE)
129-146: Enhance troubleshooting guidanceConsider adding specific steps to diagnose which class is missing a codec registration. For example:
- How to identify the problematic class from the stack trace
- How to check if a codec is registered for a specific class
224-224: Remove or clarify incomplete questionThe line ends with a question mark and seems incomplete. Consider removing the question mark or completing the thought.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/website/docs/usage/codecs.md(1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/codecs.md
[grammar] ~21-~21: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...egistration The use of codecs requires to register the codecs for the classes you want to ...
(ALLOW_TO)
[grammar] ~63-~63: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...
(ALLOW_TO)
[uncategorized] ~88-~88: Possible missing comma found.
Context: ...s a special support to import mxGraph models which you a different XML structure (ma...
(AI_HYDRA_LEO_MISSING_COMMA)
[grammar] ~88-~88: A verb may be missing between “you” and “a”, or a word may be misspelled.
Context: ...upport to import mxGraph models which you a different XML structure (mainly because...
(PRP_THE)
🔇 Additional comments (1)
packages/website/docs/usage/codecs.md (1)
151-201: Well-documented custom objects section
The section provides clear examples and properly attributes the original content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/website/docs/usage/codecs.md (3)
3-3: Enhance the description to be more informativeConsider expanding the description to better reflect the content, for example: "Learn how to use codecs for serializing and deserializing maxGraph objects in XML format."
68-70: Improve sentence structureThe current construction "requires - to register" is grammatically awkward. Consider revising to:
"As explained above, typical usage of theCodecclass requires you to:
- register the codecs for the classes you want to encode/decode, here with
registerModelCodecs- call the
encodeordecodemethod"🧰 Tools
🪛 LanguageTool
[grammar] ~69-~69: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of theCodecclass requires - to register the codecs for the classes you want to ...(ALLOW_TO)
126-126: Fix markdown code fenceThe code block is closed with four backticks (``````) while it was opened with three (```). This inconsistency might cause rendering issues in some markdown processors. Please use three backticks consistently.
-```` +```
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/website/docs/usage/codecs.md(1 hunks)packages/website/docs/usage/migrate-from-mxgraph.md(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/website/docs/usage/migrate-from-mxgraph.md
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/codecs.md
[grammar] ~69-~69: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...
(ALLOW_TO)
🔇 Additional comments (2)
packages/website/docs/usage/codecs.md (2)
47-61: Fix inconsistencies in code example
The code example contains several issues that need to be addressed:
- Line 54: Uses
resultinstead ofnode - Line 60: Uses undefined
objectvariable
1-235: Well-structured and comprehensive documentation!
The documentation provides a thorough explanation of the Codec feature, including:
- Clear introduction and concepts
- Detailed registration process
- Practical code examples
- Troubleshooting guidance
- Links to examples and demos
The content is well-organized and will be valuable for users implementing the Codec feature.
🧰 Tools
🪛 LanguageTool
[grammar] ~69-~69: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...
(ALLOW_TO)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
packages/website/docs/usage/codecs.md (5)
3-3: Enhance the documentation descriptionConsider expanding the description to better reflect the content and purpose of this page. For example:
"Guide to using codecs for serializing and deserializing maxGraph objects in XML format."-description: How-to use codecs. +description: Guide to using codecs for serializing and deserializing maxGraph objects in XML format.
69-71: Improve sentence structure for clarityThe current wording is a bit awkward. Consider restructuring the sentence for better readability.
-As explained above, the typical usage of the `Codec` class requires -- to register the codecs for the classes you want to encode/decode, here with `registerModelCodecs` -- to call the `encode` or `decode` method +As explained above, the typical usage of the `Codec` class requires you to: +- Register the codecs for the classes you want to encode/decode (using `registerModelCodecs`) +- Call the `encode` or `decode` method🧰 Tools
🪛 LanguageTool
[grammar] ~70-~70: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of theCodecclass requires - to register the codecs for the classes you want to ...(ALLOW_TO)
102-123: Add explanation of mxGraph model structureConsider adding a brief explanation of the key elements in the mxGraph model structure (e.g., what
mxCell,mxGeometry, etc. represent) to help users understand the XML format they need to provide.
136-153: Enhance troubleshooting guidanceConsider adding more specific debugging steps to help users identify which codec is missing:
- How to identify the unregistered class from the stack trace
- Common classes that require registration
- How to verify if a codec is registered
215-236: Organize examples by use caseConsider grouping the examples into categories for easier navigation:
- Basic Usage Examples
- Custom Data Examples
- Migration Examples
- Integration Examples
This would help users find relevant examples more quickly.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/website/docs/usage/codecs.md(1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/codecs.md
[grammar] ~70-~70: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...
(ALLOW_TO)
🔇 Additional comments (1)
packages/website/docs/usage/codecs.md (1)
48-62: LGTM! Code example is now correct
The code example properly demonstrates the encode/decode process with clear variable naming and correct usage of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/website/docs/usage/codecs.md (3)
15-15: Fix grammar in introductionThe verb "maps" should agree with the plural subject "classes".
-The serialization/deserialization process is based on `Codec` classes that maps the maxGraph objects to XML nodes and attributes. +The serialization/deserialization process is based on `Codec` classes that map the maxGraph objects to XML nodes and attributes.🧰 Tools
🪛 LanguageTool
[uncategorized] ~15-~15: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...rocess is based onCodecclasses that maps the maxGraph objects to XML nodes and a...(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)
48-62: Enhance code example clarityWhile the code example is functionally correct, consider these improvements for better clarity:
- Add comments explaining what each step does
- Add type annotations for better understanding
import { Codec, popup, xmlUtils } from '@mxgraph/core'; // encode/export const sourceObject = {}; // your object const encoder = new Codec(); +// Convert object to XML node const node = encoder.encode(sourceObject); +// Convert XML node to pretty-printed string const encodedXml = xmlUtils.getPrettyXml(node); // decode/import -const xml = '...'; // your XML string +const xml: string = '...'; // your XML string +// Object to populate with decoded data const targetObject = {}; // object to decode into const decoder = new Codec(); +// Parse XML string into DOM document const doc = xmlUtils.parseXml(input); +// Decode XML into target object new Codec(doc).decode(doc.documentElement, targetObject);
74-74: Fix grammar in ModelXmlSerializer descriptionThe verb "provide" should agree with the singular subject "It".
-It registers codecs under the hood and provide a simpler syntax. +It registers codecs under the hood and provides a simpler syntax.🧰 Tools
🪛 LanguageTool
[uncategorized] ~74-~74: This verb does not appear to agree with the subject. Consider using a different form.
Context: ... It registers codecs under the hood and provide a simpler syntax. The code becomes: `...(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/website/docs/usage/codecs.md(1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/codecs.md
[uncategorized] ~15-~15: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...rocess is based on Codec classes that maps the maxGraph objects to XML nodes and a...
(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)
[uncategorized] ~74-~74: This verb does not appear to agree with the subject. Consider using a different form.
Context: ... It registers codecs under the hood and provide a simpler syntax. The code becomes: `...
(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)
[uncategorized] ~97-~97: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...ability with draw.io/diagrams.net and ease the migration from mxGraph. Here is ...
(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)
🔇 Additional comments (5)
packages/website/docs/usage/codecs.md (5)
21-40: Well-structured explanation of codec registration!
The section effectively communicates the registration requirements, version changes, and performance considerations.
73-90: Excellent explanation of ModelXmlSerializer!
The section effectively demonstrates the simplified approach compared to direct Codec usage.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~74-~74: This verb does not appear to agree with the subject. Consider using a different form.
Context: ... It registers codecs under the hood and provide a simpler syntax. The code becomes: `...
(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)
134-154: Well-documented troubleshooting guide!
The section effectively explains the common "maximum call stack" error and provides clear steps to resolve it.
169-213: Comprehensive explanation of custom object encoding!
The section effectively demonstrates the default encoding scheme with clear examples.
215-236: Excellent collection of practical examples!
The section provides a comprehensive set of examples with both live demos and source code references.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (7)
packages/website/docs/usage/codecs.md (7)
1-17: Add version compatibility information to the introductionConsider adding a note about which versions of maxGraph this documentation applies to, helping users understand version compatibility upfront.
19-40: Add a code example for codec registrationConsider adding a basic code example showing how to register codecs, particularly for users who might need to register custom codecs. This would complement the existing explanation of the registration functions.
// Example to add: import { CodecRegistry, registerCoreCodecs } from '@mxgraph/core'; // Register all core codecs registerCoreCodecs(); // Or register a custom codec CodecRegistry.register('MyCustomClass', new MyCustomCodec());
48-62: Enhance code example with type annotationsConsider adding TypeScript type annotations to make the example more clear and type-safe.
-const sourceObject = {}; // your object -const targetObject = {}; // object to decode into +interface YourObject { + // Define your object structure +} +const sourceObject: YourObject = {}; // your object +const targetObject: YourObject = {}; // object to decode into
102-123: Enhance mxGraph import exampleThe example XML could be more realistic by:
- Adding comments explaining the structure
- Including more common mxGraph attributes like style
- Showing error handling
const mxGraphModelAsXml = `<mxGraphModel> <root> + <!-- Root element required by mxGraph --> <mxCell id="0"/> + <!-- Default parent element --> <mxCell id="1" parent="0"/> + <!-- Example vertex with style --> - <mxCell id="2" vertex="1" parent="1" value="Vertex #2"> + <mxCell id="2" vertex="1" parent="1" value="Vertex #2" style="rounded=1;whiteSpace=wrap;html=1;"> <mxGeometry x="380" y="20" width="140" height="30" as="geometry"/> </mxCell>
134-154: Expand troubleshooting sectionConsider adding more common troubleshooting scenarios:
- Circular references in objects
- Missing required attributes
- Invalid XML structure
- Type mismatches during decode
175-182: Add more complex custom object examplesConsider adding examples that demonstrate:
- Nested custom objects
- Custom array handling
- Date serialization
- Custom attribute mapping
215-236: Organize examples by use caseConsider organizing the examples into categories:
- Basic Usage
- Advanced Features
- Migration from mxGraph
- Custom Implementation
This would help users find relevant examples more easily.
Briefly explain what they do and how to configure them.
Also improve the Codecs paragraph in the "migrate from mxGraph" guide
Tasks
Summary by CodeRabbit
Release Notes
New Features
Codecfeature for XML serialization and deserialization.mxGraphtomaxGraph, providing clearer guidelines and updated class names.Documentation
maxGraph.Bug Fixes
tutorial.htmlfile related to encoding schemes.