fix: project cereal cleanup (#5398)

* fix: make exception constructors package

* fix: rename blocks.load to blocks.append

* fix: inline docs

* fix: consistency in block serialization

* fix: remove unexported functions

* fix: interface requires

* fix: tag TODO with issue number
This commit is contained in:
Beka Westberg
2021-09-10 21:05:17 +00:00
committed by alschmiedt
parent 0e0c5fea0e
commit e954193009
16 changed files with 102 additions and 143 deletions

View File

@@ -757,7 +757,7 @@ Connection.prototype.createShadowBlock_ = function(attemptToConnect) {
let blockShadow;
if (shadowState) {
blockShadow = blocks.loadInternal(
blockShadow = blocks.appendInternal(
shadowState,
parentBlock.workspace,
{

View File

@@ -94,7 +94,7 @@ BlockCreate.prototype.fromJson = function(json) {
BlockCreate.prototype.run = function(forward) {
const workspace = this.getEventWorkspace_();
if (forward) {
blocks.load(this.json, workspace);
blocks.append(this.json, workspace);
} else {
for (let i = 0; i < this.ids.length; i++) {
const id = this.ids[i];

View File

@@ -117,7 +117,7 @@ BlockDelete.prototype.run = function(forward) {
}
}
} else {
blocks.load(this.oldJson, workspace);
blocks.append(this.oldJson, workspace);
}
};

View File

@@ -674,7 +674,7 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) {
* Create a block from the xml and permanently disable any blocks that were
* defined as disabled.
* @param {!toolbox.BlockInfo} blockInfo The info of the block.
* @return {!BlockSvg} The block created from the blockXml.
* @return {!BlockSvg} The block created from the blockInfo.
* @private
*/
Flyout.prototype.createFlyoutBlock_ = function(blockInfo) {
@@ -694,7 +694,7 @@ Flyout.prototype.createFlyoutBlock_ = function(blockInfo) {
blockInfo['enabled'] =
blockInfo['disabled'] !== 'true' && blockInfo['disabled'] !== true;
}
block = blocks.load(
block = blocks.append(
/** @type {blocks.State} */ (blockInfo),this.workspace_);
}
}
@@ -1077,7 +1077,7 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) {
const json = /** @type {!blocks.State} */ (blocks.save(oldBlock));
// Normallly this resizes leading to weird jumps. Save it for terminateDrag.
targetWorkspace.setResizesEnabled(false);
const block = /** @type {!BlockSvg} */ (blocks.load(json, targetWorkspace));
const block = /** @type {!BlockSvg} */ (blocks.append(json, targetWorkspace));
this.positionNewBlock_(oldBlock, block);

View File

@@ -19,17 +19,17 @@ const Workspace = goog.requireType('Blockly.Workspace');
/**
* Serializes and deserializes a plugin.
* Serializes and deserializes a plugin or system.
* @interface
*/
class ISerializer {
constructor() {
/**
* A priority value used to determine the order of deserializing plugins.
* A priority value used to determine the order of deserializing state.
* 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
* If two serializers have the same priority, they are deserialized in an
* arbitrary order relative to each other.
* @type {number}
*/
@@ -39,10 +39,10 @@ class ISerializer {
/* eslint-disable no-unused-vars, valid-jsdoc */
/**
* Saves the state of the plugin.
* @param {!Workspace} workspace The workspace the plugin to serialize is
* Saves the state of the plugin or system.
* @param {!Workspace} workspace The workspace the system to serialize is
* associated with.
* @return {?} A JS object containing the plugin's state, or null if
* @return {?} A JS object containing the system's state, or null if
* there is no state to record.
*/
save(workspace) {}
@@ -50,17 +50,17 @@ class ISerializer {
/* eslint-enable valid-jsdoc */
/**
* Loads the state of the plugin.
* @param {?} state The state of the plugin to deserialize. This will always
* Loads the state of the plugin or system.
* @param {?} state The state of the system to deserialize. This will always
* be non-null.
* @param {!Workspace} workspace The workspace the plugin to deserialize is
* @param {!Workspace} workspace The workspace the system 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
* Clears the state of the plugin or system.
* @param {!Workspace} workspace The workspace the system to clear the state
* of is associated with.
*/
clear(workspace) {}

View File

@@ -145,7 +145,7 @@ Type.SERIALIZER = new Type('serializer');
* an already registered item.
* @throws {Error} if the type or name is empty, a name with the given type has
* already been registered, or if the given class or object is not valid for
* it's type.
* its type.
* @template T
*/
const register = function(type, name, registryItem, opt_allowOverrides) {

View File

@@ -20,7 +20,7 @@ const Block = goog.requireType('Blockly.Block');
const Connection = goog.requireType('Blockly.Connection');
const Events = goog.require('Blockly.Events');
// eslint-disable-next-line no-unused-vars
const {ISerializer} = goog.requireType('Blockly.serialization.ISerializer');
const {ISerializer} = goog.require('Blockly.serialization.ISerializer');
const Size = goog.require('Blockly.utils.Size');
// eslint-disable-next-line no-unused-vars
const Workspace = goog.requireType('Blockly.Workspace');
@@ -30,7 +30,7 @@ const priorities = goog.require('Blockly.serialization.priorities');
const serializationRegistry = goog.require('Blockly.serialization.registry');
// TODO: Remove this once lint is fixed.
// TODO(#5160): Remove this once lint is fixed.
/* eslint-disable no-use-before-define */
/**
@@ -52,9 +52,6 @@ exports.ConnectionState = ConnectionState;
* y: (number|undefined),
* collapsed: (boolean|undefined),
* enabled: (boolean|undefined),
* editable: (boolean|undefined),
* deletable: (boolean|undefined),
* movable: (boolean|undefined),
* inline: (boolean|undefined),
* data: (string|undefined),
* extra-state: (*|undefined),
@@ -148,8 +145,8 @@ const saveAttributes = function(block, state) {
/**
* Adds the coordinates of the given block to the given state object.
* @param {!Block} block The block to base the coordinates on
* @param {!State} state The state object to append to
* @param {!Block} block The block to base the coordinates on.
* @param {!State} state The state object to append to.
*/
const saveCoords = function(block, state) {
const workspace = block.workspace;
@@ -206,19 +203,17 @@ const saveIcons = function(block, state) {
* state).
*/
const saveFields = function(block, state, doFullSerialization) {
let hasFieldState = false;
const fields = Object.create(null);
for (let i = 0; i < block.inputList.length; i++) {
const input = block.inputList[i];
for (let j = 0; j < input.fieldRow.length; j++) {
const field = input.fieldRow[j];
if (field.isSerializable()) {
hasFieldState = true;
fields[field.name] = field.saveState(doFullSerialization);
}
}
}
if (hasFieldState) {
if (Object.keys(fields).length) {
state['fields'] = fields;
}
};
@@ -301,10 +296,10 @@ const saveConnection = function(connection, doFullSerialization) {
* by the user. False by default.
* @return {!Block} The block that was just loaded.
*/
const load = function(state, workspace, {recordUndo = false} = {}) {
return loadInternal(state, workspace, {recordUndo});
const append = function(state, workspace, {recordUndo = false} = {}) {
return appendInternal(state, workspace, {recordUndo});
};
exports.load = load;
exports.append = append;
/**
* Loads the block represented by the given state into the given workspace.
@@ -318,13 +313,13 @@ exports.load = load;
* (boolean|undefined), recordUndo: (boolean|undefined)}=} param1
* parentConnection: If provided, the system will attempt to connect the
* block to this connection after it is created. Undefined by default.
* isShadow: The block will be set to a shadow block after it is created.
* False by default.
* isShadow: If true, the block will be set to a shadow block after it is
* created. False by default.
* recordUndo: If true, events triggered by this function will be undo-able
* by the user. False by default.
* @return {!Block} The block that was just loaded.
* @return {!Block} The block that was just appended.
*/
const loadInternal = function(
const appendInternal = function(
state,
workspace,
{
@@ -341,7 +336,7 @@ const loadInternal = function(
}
Events.disable();
const block = loadPrivate(state, workspace, {parentConnection, isShadow});
const block = appendPrivate(state, workspace, {parentConnection, isShadow});
Events.enable();
Events.fire(new (Events.get(Events.BLOCK_CREATE))(block));
@@ -361,24 +356,24 @@ const loadInternal = function(
return block;
};
/** @package */
exports.loadInternal = loadInternal;
exports.appendInternal = appendInternal;
/**
* Loads the block represented by the given state into the given workspace.
* This is defined privately so that it can be called recursively without firing
* eroneous events. Events (and other things we only want to occur on the top
* block) are handled by loadInternal.
* block) are handled by appendInternal.
* @param {!State} state The state of a block to deserialize into the workspace.
* @param {!Workspace} workspace The workspace to add the block to.
* @param {{parentConnection: (!Connection|undefined), isShadow:
* (boolean|undefined), recordUndo: (boolean|undefined)}=} param1
* @param {{parentConnection: (!Connection|undefined),
* isShadow: (boolean|undefined)}=} param1
* parentConnection: If provided, the system will attempt to connect the
* block to this connection after it is created. Undefined by default.
* isShadow: The block will be set to a shadow block after it is created.
* False by default.
* @return {!Block} The block that was just loaded.
* @return {!Block} The block that was just appended.
*/
const loadPrivate = function(
const appendPrivate = function(
state,
workspace,
{
@@ -460,9 +455,9 @@ const loadExtraState = function(block, state) {
/**
* Attempts to connect the block to the parent connection, if it exists.
* @param {(!Connection|undefined)} parentConnection The parent connnection to
* @param {(!Connection|undefined)} parentConnection The parent connection to
* try to connect the block to.
* @param {!Block} child The block to try to conecnt to the parent.
* @param {!Block} child The block to try to connect to the parent.
* @param {!State} state The state which defines the given block
*/
const tryToConnectParent = function(parentConnection, child, state) {
@@ -591,7 +586,7 @@ const loadNextBlocks = function(block, state) {
/**
* Applies the state defined by connectionState to the given connection, ie
* assigns shadows and attaches child blocks.
* @param {!Connection} connection The connection to serialize the
* @param {!Connection} connection The connection to deserialize the
* connected blocks of.
* @param {!ConnectionState} connectionState The object containing the state of
* any connected shadow block, or any connected real block.
@@ -601,7 +596,7 @@ const loadConnection = function(connection, connectionState) {
connection.setShadowState(connectionState['shadow']);
}
if (connectionState['block']) {
loadPrivate(
appendPrivate(
connectionState['block'],
connection.getSourceBlock().workspace,
{parentConnection: connection});
@@ -627,9 +622,8 @@ const initBlock = function(block, rendered) {
}
};
// Aliases to disambiguate saving/loading within the serializer.
// Alias to disambiguate saving within the serializer.
const saveBlock = save;
const loadBlock = load;
/**
* Serializer for saving and loading block state.
@@ -651,18 +645,18 @@ class BlockSerializer {
* the workspace's blocks, or null if there are no blocks.
*/
save(workspace) {
const blockState = [];
const blockStates = [];
for (const block of workspace.getTopBlocks(false)) {
const state = saveBlock(
block, {addCoordinates: true, doFullSerialization: false});
if (state) {
blockState.push(state);
blockStates.push(state);
}
}
if (blockState.length) {
if (blockStates.length) {
return {
'languageVersion': 0, // Currently unused.
'blocks': blockState
'blocks': blockStates
};
}
return null;
@@ -678,7 +672,7 @@ class BlockSerializer {
load(state, workspace) {
const blockStates = state['blocks'];
for (const state of blockStates) {
loadBlock(state, workspace, {recordUndo: Events.getRecordUndo()});
append(state, workspace, {recordUndo: Events.getRecordUndo()});
}
}

View File

@@ -27,6 +27,7 @@ exports.DeserializationError = DeserializationError;
class MissingBlockType extends DeserializationError {
/**
* @param {!State} state The state object which is missing the block type.
* @package
*/
constructor(state) {
super(`Expected to find a 'type' property, defining the block type`);
@@ -50,6 +51,7 @@ class MissingConnection extends DeserializationError {
* 'IF0', or 'next'.
* @param {!Blockly.Block} block The block missing the connection.
* @param {!State} state The state object containing the bad connection.
* @package
*/
constructor(connection, block, state) {
super(`The block ${block.toDevString()} is missing a(n) ${connection}
@@ -82,6 +84,7 @@ class BadConnectionCheck extends DeserializationError {
* @param {!Blockly.Block} childBlock The child block that could not connect
* to its parent.
* @param {!State} childState The state object representing the child block.
* @package
*/
constructor(reason, childConnection, childBlock, childState) {
super(`The block ${childBlock.toDevString()} could not connect its
@@ -112,6 +115,7 @@ exports.BadConnectionCheck = BadConnectionCheck;
class RealChildOfShadow extends DeserializationError {
/**
* @param {!State} state The state object representing the real block.
* @package
*/
constructor(state) {
super(`Encountered a real block which is defined as a child of a shadow

View File

@@ -13,11 +13,8 @@
goog.module('Blockly.serialization.variables');
goog.module.declareLegacyNamespace();
const Events = goog.require('Blockly.Events');
// eslint-disable-next-line no-unused-vars
const {ISerializer} = goog.requireType('Blockly.serialization.ISerializer');
// eslint-disable-next-line no-unused-vars
const VariableModel = goog.requireType('Blockly.VariableModel');
const {ISerializer} = goog.require('Blockly.serialization.ISerializer');
// eslint-disable-next-line no-unused-vars
const Workspace = goog.requireType('Blockly.Workspace');
const priorities = goog.require('Blockly.serialization.priorities');
@@ -35,45 +32,6 @@ const serializationRegistry = goog.require('Blockly.serialization.registry');
var State;
exports.State = State;
/**
* Returns the state of the variable as a plain JavaScript object.
* @param {!VariableModel} variableModel The variable to serialize.
* @return {!State} The serialized state of the variable.
*/
const saveVariable = function(variableModel) {
const state = {
'name': variableModel.name,
'id': variableModel.getId()
};
if (variableModel.type) {
state['type'] = variableModel.type;
}
return state;
};
/**
* Loads the variable represented by the given state into the given workspace.
* @param {!State} state The state of a variable to deserialize into the
* workspace.
* @param {!Workspace} workspace The workspace to add the variable to.
* @param {{recordUndo: (boolean|undefined)}=} param1
* recordUndo: If true, events triggered by this function will be undo-able
* by the user. False by default.
*/
const loadVariable = function(state, workspace, {recordUndo = false} = {}) {
const prevRecordUndo = Events.getRecordUndo();
Events.setRecordUndo(recordUndo);
const existingGroup = Events.getGroup();
if (!existingGroup) {
Events.setGroup(true);
}
workspace.createVariable(state['name'], state['type'], state['id']);
Events.setGroup(existingGroup);
Events.setRecordUndo(prevRecordUndo);
};
/**
* Serializer for saving and loading variable state.
* @implements {ISerializer}
@@ -96,7 +54,14 @@ class VariableSerializer {
save(workspace) {
const variableStates = [];
for (const variable of workspace.getAllVariables()) {
variableStates.push(saveVariable(variable));
const state = {
'name': variable.name,
'id': variable.getId()
};
if (variable.type) {
state['type'] = variable.type;
}
variableStates.push(state);
}
return variableStates.length ? variableStates : null;
}
@@ -109,13 +74,13 @@ class VariableSerializer {
*/
load(state, workspace) {
for (const varState of state) {
loadVariable(varState, workspace, {recordUndo: Events.getRecordUndo()});
workspace.createVariable(
varState['name'], varState['type'], varState['id']);
}
}
/**
* Disposes of any variables or potential variables that exist on the
* workspace.
* Disposes of any variables that exist on the workspace.
* @param {!Workspace} workspace The workspace to clear the variables of.
*/
clear(workspace) {

View File

@@ -39,9 +39,6 @@ const userAgent = goog.require('Blockly.utils.userAgent');
* x: (number|undefined),
* y: (number|undefined),
* collapsed: (boolean|undefined),
* editable: (boolean|undefined),
* deletable: (boolean|undefined),
* movable: (boolean|undefined),
* inline: (boolean|undefined),
* data: (string|undefined),
* extra-state: (*|undefined),

View File

@@ -1550,7 +1550,7 @@ WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock, jsonBlock) {
blockX = parseInt(xmlBlock.getAttribute('x'), 10);
blockY = parseInt(xmlBlock.getAttribute('y'), 10);
} else if (jsonBlock) {
block = blocks.load(jsonBlock, this);
block = blocks.append(jsonBlock, this);
blockX = jsonBlock['x'] || 10;
blockY = jsonBlock['y'] || 10;
}

View File

@@ -197,11 +197,11 @@ goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Ren
goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.serialization.blocks', 'Blockly.serialization.registry', 'Blockly.serialization.variables', 'Blockly.serialization.workspaces', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']);
goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar'], ['Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/scrollbar_pair.js', ['Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Scrollbar', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/serialization/blocks.js', ['Blockly.serialization.blocks'], ['Blockly.Events', 'Blockly.Xml', 'Blockly.inputTypes', 'Blockly.serialization.exceptions', 'Blockly.serialization.priorities', 'Blockly.serialization.registry', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/serialization/blocks.js', ['Blockly.serialization.blocks'], ['Blockly.Events', 'Blockly.Xml', 'Blockly.inputTypes', 'Blockly.serialization.ISerializer', 'Blockly.serialization.exceptions', 'Blockly.serialization.priorities', 'Blockly.serialization.registry', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/serialization/exceptions.js', ['Blockly.serialization.exceptions'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/serialization/priorities.js', ['Blockly.serialization.priorities'], [], {'module': 'goog'});
goog.addDependency('../../core/serialization/registry.js', ['Blockly.serialization.registry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/serialization/variables.js', ['Blockly.serialization.variables'], ['Blockly.Events', 'Blockly.serialization.priorities', 'Blockly.serialization.registry'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/serialization/variables.js', ['Blockly.serialization.variables'], ['Blockly.serialization.ISerializer', 'Blockly.serialization.priorities', 'Blockly.serialization.registry'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/serialization/workspaces.js', ['Blockly.serialization.workspaces'], ['Blockly.Events', 'Blockly.Workspace', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.clipboard', 'Blockly.common', 'Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});

View File

@@ -21,7 +21,7 @@ suite('Block Create Event', function() {
test('Create shadow on disconnect', function() {
Blockly.Events.disable();
const block = Blockly.serialization.blocks.load(
const block = Blockly.serialization.blocks.append(
{
"type": "text_print",
"inputs": {

View File

@@ -1352,18 +1352,18 @@ suite('Connection', function() {
suite('Add - No Block Connected', function() {
// These are defined separately in each suite.
function createRowBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'row_block', 'id': 'id0'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'row_block', 'id': 'id0'}, workspace);
}
function createStatementBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'statement_block', 'id': 'id0'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'statement_block', 'id': 'id0'}, workspace);
}
function createStackBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'stack_block', 'id': 'id0'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'stack_block', 'id': 'id0'}, workspace);
}
test('Value', function() {
@@ -1551,7 +1551,6 @@ suite('Connection', function() {
'</block>'
);
});
test('Multiple Next', function() {
var parent = createStackBlock(this.workspace);
parent.nextConnection.setShadowState({
@@ -1601,7 +1600,7 @@ suite('Connection', function() {
suite('Add - With Block Connected', function() {
// These are defined separately in each suite.
function createRowBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'row_block',
'id': 'id0',
@@ -1618,7 +1617,7 @@ suite('Connection', function() {
}
function createStatementBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'statement_block',
'id': 'id0',
@@ -1635,7 +1634,7 @@ suite('Connection', function() {
}
function createStackBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'stack_block',
'id': 'id0',
@@ -1906,18 +1905,18 @@ suite('Connection', function() {
suite('Add - With Shadow Connected', function() {
// These are defined separately in each suite.
function createRowBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'row_block', 'id': 'id0'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'row_block', 'id': 'id0'}, workspace);
}
function createStatementBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'statement_block', 'id': 'id0'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'statement_block', 'id': 'id0'}, workspace);
}
function createStackBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'stack_block', 'id': 'id0'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'stack_block', 'id': 'id0'}, workspace);
}
test('Value', function() {
@@ -2218,7 +2217,7 @@ suite('Connection', function() {
suite('Remove - No Block Connected', function() {
// These are defined separately in each suite.
function createRowBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'row_block',
'id': 'id0',
@@ -2235,7 +2234,7 @@ suite('Connection', function() {
}
function createStatementBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'statement_block',
'id': 'id0',
@@ -2252,7 +2251,7 @@ suite('Connection', function() {
}
function createStackBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'stack_block',
'id': 'id0',
@@ -2318,7 +2317,7 @@ suite('Connection', function() {
suite('Remove - Block Connected', function() {
// These are defined separately in each suite.
function createRowBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'row_block',
'id': 'id0',
@@ -2339,7 +2338,7 @@ suite('Connection', function() {
}
function createStatementBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'statement_block',
'id': 'id0',
@@ -2360,7 +2359,7 @@ suite('Connection', function() {
}
function createStackBlocks(workspace) {
return Blockly.serialization.blocks.load(
return Blockly.serialization.blocks.append(
{
'type': 'stack_block',
'id': 'id0',
@@ -2436,18 +2435,18 @@ suite('Connection', function() {
suite('Add - Connect & Disconnect - Remove', function() {
// These are defined separately in each suite.
function createRowBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'row_block'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'row_block'}, workspace);
}
function createStatementBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'statement_block'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'statement_block'}, workspace);
}
function createStackBlock(workspace) {
return Blockly.serialization.blocks
.load({'type': 'stack_block'}, workspace);
return Blockly.serialization.blocks.append(
{'type': 'stack_block'}, workspace);
}
test('Value', function() {

View File

@@ -454,7 +454,7 @@ suite('Variable Fields', function() {
test('ID', function() {
this.workspace.createVariable('test', '', 'id1');
var block = Blockly.serialization.blocks.load({
var block = Blockly.serialization.blocks.append({
'type': 'variables_get',
'fields': {
'VAR': {
@@ -470,7 +470,7 @@ suite('Variable Fields', function() {
});
test('Name, untyped', function() {
var block = Blockly.serialization.blocks.load({
var block = Blockly.serialization.blocks.append({
'type': 'variables_get',
'fields': {
'VAR': {
@@ -486,7 +486,7 @@ suite('Variable Fields', function() {
});
test('Name, typed', function() {
var block = Blockly.serialization.blocks.load({
var block = Blockly.serialization.blocks.append({
'type': 'variables_get',
'fields': {
'VAR': {

View File

@@ -362,7 +362,7 @@ suite('JSO Deserialization', function() {
'x': 42,
'y': 42
};
Blockly.serialization.blocks.load(state, this.workspace);
Blockly.serialization.blocks.append(state, this.workspace);
assertEventFired(
this.eventsFireStub,
Blockly.Events.BlockCreate,
@@ -378,8 +378,8 @@ suite('JSO Deserialization', function() {
'x': 42,
'y': 42
};
Blockly.serialization.blocks
.load(state, this.workspace, {'recordUndo': true});
Blockly.serialization.blocks.append(
state, this.workspace, {'recordUndo': true});
assertEventFired(
this.eventsFireStub,
Blockly.Events.BlockCreate,
@@ -396,7 +396,7 @@ suite('JSO Deserialization', function() {
'y': 42
};
Blockly.Events.setGroup('my group');
Blockly.serialization.blocks.load(state, this.workspace);
Blockly.serialization.blocks.append(state, this.workspace);
assertEventFired(
this.eventsFireStub,
Blockly.Events.BlockCreate,
@@ -700,7 +700,7 @@ suite('JSO Deserialization', function() {
}
};
const block = Blockly.serialization.blocks.load(
const block = Blockly.serialization.blocks.append(
{
'type': 'test_block',
'extraState': '<mutation value="some value"></mutation>',