-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: correct workspace comment serialization docs #10270
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
Open
Johnkothapalli
wants to merge
1
commit into
RaspberryPiFoundation:main
Choose a base branch
from
Johnkothapalli:docs/workspace-comment-serialization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+19
−25
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,10 +25,10 @@ For information on how to migrate to JSON from XML, see the [migration | |
| guide]. | ||
| ::: | ||
|
|
||
| The JSON serialization system is made up of multiple serializers. There are | ||
| built-in serializers for blocks and variables, and you can also register | ||
| additional serializers. Each serializer is responsible for serializing and | ||
| deserializing the state of a particular plugin or system. | ||
| The JSON serialization system is made up of multiple serializers. It includes | ||
| built-in serializers for blocks, variables, and workspace comments, and you can | ||
| also register additional serializers. Each serializer is responsible for | ||
| serializing and deserializing the state of a particular plugin or system. | ||
|
|
||
| ### Saving and Loading | ||
|
|
||
|
|
@@ -104,6 +104,7 @@ The order for deserialization of built-in serializers is: | |
| value inputs and statement inputs. Individual inputs are deserialized in | ||
| an _arbitrary order_. | ||
| 4. **Next blocks are deserialized.** | ||
| 6. **Workspace comments are deserialized.** | ||
|
|
||
| ### When to save extra state | ||
|
|
||
|
|
@@ -142,21 +143,20 @@ documentation. | |
|
|
||
| The JSON system allows you to register serializers which serialize and | ||
| deserialize some state. Blockly's built-in serializers take care of serializing | ||
| information about blocks and variables, but if you want to serialize other | ||
| information you'll need to add your own serializer. For example, workspace-level | ||
| comments are not serialized by default by the JSON system. If you want to | ||
| serialize them, you will need to register an additional serializer. | ||
| information about blocks, variables, and workspace comments. If you want to | ||
| serialize other information, such as the state of a plugin, you'll need to add | ||
| your own serializer. | ||
|
|
||
| Additional serializers are often used to serialize and deserialize the state of | ||
| a plugin. | ||
|
|
||
| ```js | ||
| Blockly.serialization.registry.register( | ||
| 'workspace-comments', // Name | ||
| 'myPlugin', // Name | ||
| { | ||
| save: saveFn, // Save function | ||
| load: loadFn, // Load function | ||
| clear: clearFn, // Clear function | ||
| save: savePluginState, // Save function | ||
| load: loadPluginState, // Load function | ||
| clear: clearPluginState, // Clear function | ||
| priority: 10, // Priority | ||
| }, | ||
| ); | ||
|
|
@@ -173,35 +173,29 @@ When you register a serializer you must provide several things: | |
| order](/guides/configure/serialization#deserialization-order). | ||
|
|
||
| You can base the priority of your serializer on the [built-in | ||
| priorities](/reference/blockly.serialization.priorities) | ||
| priorities](/reference/blockly.serialization_namespace.priorities_namespace/#serializationpriorities-namespace) | ||
|
|
||
| When `Blockly.serialization.workspaces.save` is called, each serializer's `save` | ||
| function will be called, and its data will be added to the final JSON output: | ||
|
|
||
| ```json | ||
| { | ||
| "blocks": { ... }, | ||
| "workspaceComments": [ // Provided by workspace-comments serializer | ||
| { | ||
| "x": 239, | ||
| "y": 31, | ||
| "text": "Add 2 + 2" | ||
| }, | ||
| // etc... | ||
| ] | ||
| "blocks": {}, | ||
| "myPlugin": {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some fake data here (it can be the same as what the |
||
| } | ||
| ``` | ||
|
|
||
| The `myPlugin` property is provided by the custom serializer. | ||
|
|
||
| When `Blockly.serialization.workspaces.load` is called, each serializer is | ||
| triggered in order of priority. Serializers with more positive priority values | ||
| are triggered before serializers with less positive priority values. | ||
|
|
||
| When a serializer is triggered, two things happen: | ||
|
|
||
| 1. The provided `clear` function is called. This ensures that the state of your | ||
| plugin/system is clean before more state is loaded. For example, the | ||
| workspace-comments serializer would remove all existing comments from the | ||
| workspace. | ||
| plugin/system is clean before more state is loaded. For example, a custom | ||
| plugin serializer would clear the plugin's existing state. | ||
| 2. The provided `load` function is called. | ||
|
|
||
| ## XML system | ||
|
|
||
Oops, something went wrong.
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.
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.
nit: add a ... between the curly braces to indicate that there's usually content here in the JSON