-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: adds hooks for serializing plugins #5276
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
Merged
BeksOmega
merged 13 commits into
RaspberryPiFoundation:project-cereal
from
BeksOmega:cereal/plugin-hooks
Aug 20, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ee63723
Reformat registry tests
BeksOmega 0b70894
Add tests for plugin hooks
BeksOmega a9df60b
Add plugin hooks for serialization
BeksOmega 8b5b911
Switch PluginSerializer to IPluginSerializer
BeksOmega 8c6848a
fix: types
BeksOmega bd16a52
fix: PR comments
BeksOmega 4b40919
fix: tests
BeksOmega 591679a
cleanup: formatting
BeksOmega 9b8e96c
fix: types
BeksOmega 07c7d46
feat: add respecting case in registry
BeksOmega ac9ca28
feat: add separate registry for serializers
BeksOmega ca8a705
fix: rename serialiation registry alias
BeksOmega fb6c90a
fix: move serializer interface into interface dir
BeksOmega 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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2021 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @fileoverview The record type for an object containing functions for | ||
| * serializing part of the workspace. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| goog.module('Blockly.serialization.ISerializer'); | ||
| goog.module.declareLegacyNamespace(); | ||
|
|
||
| // eslint-disable-next-line no-unused-vars | ||
| const Workspace = goog.requireType('Blockly.Workspace'); | ||
|
|
||
|
|
||
| /** | ||
| * Serializes and deserializes a plugin. | ||
| * @interface | ||
| */ | ||
| class ISerializer { | ||
| constructor() { | ||
| /** | ||
| * A priority value used to determine the order of deserializing plugins. | ||
| * More positive priorities are deserialized before less positive | ||
| * priorities. Eg if you have priorities (0, -10, 10, 100) the order of | ||
| * deserialiation will be (100, 10, 0, -10). | ||
| * If two plugins have the same priority, they are deserialized in an | ||
| * arbitrary order relative to each other. | ||
| * @type {number} | ||
| */ | ||
| this.priority; | ||
| } | ||
|
|
||
| /* eslint-disable no-unused-vars, valid-jsdoc */ | ||
|
|
||
| /** | ||
| * Saves the state of the plugin. | ||
| * @param {!Workspace} workspace The workspace the plugin to serialize is | ||
| * associated with. | ||
| * @return {?} A JS object containing the plugin's state, or null if | ||
| * there is no state to record. | ||
| */ | ||
| save(workspace) {} | ||
|
|
||
| /* eslint-enable valid-jsdoc */ | ||
|
|
||
| /** | ||
| * Loads the state of the plugin. | ||
| * @param {?} state The state of the plugin to deserialize. This will always | ||
| * be non-null. | ||
| * @param {!Workspace} workspace The workspace the plugin to deserialize is | ||
| * associated with. | ||
| */ | ||
| load(state, workspace) {} | ||
|
|
||
| /** | ||
| * Clears the state of the plugin. | ||
| * @param {!Workspace} workspace The workspace the plugin to clear the state | ||
| * of is associated with. | ||
| */ | ||
| clear(workspace) {} | ||
|
|
||
| /* eslint-enable no-unused-vars */ | ||
| } | ||
|
|
||
| exports.ISerializer = ISerializer; |
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2021 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @fileoverview Includes constants for the priorities of different plugin | ||
| * serializers. Higher priorities are deserialized first. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * The top level namespace for priorities of plugin serializers. | ||
| * @namespace Blockly.serialization.priorities | ||
| */ | ||
| goog.module('Blockly.serialization.priorities'); | ||
| goog.module.declareLegacyNamespace(); | ||
|
|
||
|
|
||
| /** | ||
| * The priority for deserializing variables. | ||
| * @type {number} | ||
| * @const | ||
| */ | ||
| exports.VARIABLES = 100; | ||
|
|
||
| /** | ||
| * The priority for deserializing blocks. | ||
| * @type {number} | ||
| * @const | ||
| */ | ||
| exports.BLOCKS = 50; |
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2021 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @fileoverview Contains functions registering serializers (eg blocks, | ||
| * variables, plugins, etc). | ||
| */ | ||
| 'use strict'; | ||
|
|
||
| goog.module('Blockly.serialization.registry'); | ||
| goog.module.declareLegacyNamespace(); | ||
|
|
||
|
|
||
| // eslint-disable-next-line no-unused-vars | ||
| const {ISerializer} = goog.requireType('Blockly.serialization.ISerializer'); | ||
| const registry = goog.require('Blockly.registry'); | ||
|
|
||
|
|
||
| /** | ||
| * Registers the given serializer so that it can be used for serialization and | ||
| * deserialization. | ||
| * @param {string} name The name of the serializer to register. | ||
| * @param {ISerializer} serializer The serializer to register. | ||
| */ | ||
| const register = function(name, serializer) { | ||
| registry.register(registry.Type.SERIALIZER, name, serializer); | ||
| }; | ||
| exports.register = register; | ||
|
|
||
| /** | ||
| * Unregisters the serializer associated with the given name. | ||
| * @param {string} name The name of the serializer to unregister. | ||
| */ | ||
| const unregister = function(name) { | ||
| registry.unregister(registry.Type.SERIALIZER, name); | ||
| }; | ||
| exports.unregister = unregister; |
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.
Uh oh!
There was an error while loading. Please reload this page.