mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
feat: adds hooks for serializing plugins (#5276)
* Reformat registry tests * Add tests for plugin hooks * Add plugin hooks for serialization * Switch PluginSerializer to IPluginSerializer * fix: types * fix: PR comments * fix: tests * cleanup: formatting * fix: types * feat: add respecting case in registry * feat: add separate registry for serializers * fix: rename serialiation registry alias * fix: move serializer interface into interface dir
This commit is contained in:
committed by
alschmiedt
parent
486123e4ff
commit
07057d087c
71
core/interfaces/i_serializer.js
Normal file
71
core/interfaces/i_serializer.js
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user