Skip to content

Commit

Permalink
fix: remove some attributes from the JSO system (google#5356)
Browse files Browse the repository at this point in the history
* fix: remove some attributes from the JSO system

Remove the deletable, movable, and editable attributes.
Normally this would be a breaking change, but because this isn't
released yet it's just a patch.

* fixup: serializer tests
  • Loading branch information
BeksOmega authored and alschmiedt committed Sep 20, 2021
1 parent 07057d0 commit 9aecac3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 104 deletions.
25 changes: 1 addition & 24 deletions core/serialization/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ exports.ConnectionState = ConnectionState;
* y: (number|undefined),
* collapsed: (boolean|undefined),
* disabled: (boolean|undefined),
* editable: (boolean|undefined),
* deletable: (boolean|undefined),
* movable: (boolean|undefined),
* inline: (boolean|undefined),
* data: (string|undefined),
* extra-state: *,
Expand Down Expand Up @@ -118,7 +115,7 @@ exports.save = save;

/**
* Adds attributes to the given state object based on the state of the block.
* Eg collapsed, disabled, editable, etc.
* Eg collapsed, disabled, inline, etc.
* @param {!Block} block The block to base the attributes on.
* @param {!State} state The state object to append to.
*/
Expand All @@ -129,21 +126,10 @@ const saveAttributes = function(block, state) {
if (!block.isEnabled()) {
state['enabled'] = false;
}
if (!block.isEditable()) {
state['editable'] = false;
}
if (!block.isDeletable() && !block.isShadow()) {
state['deletable'] = false;
}
if (!block.isMovable() && !block.isShadow()) {
state['movable'] = false;
}

if (block.inputsInline !== undefined &&
block.inputsInline !== block.inputsInlineDefault) {
state['inline'] = block.inputsInline;
}

// Data is a nullable string, so we don't need to worry about falsy values.
if (block.data) {
state['data'] = block.data;
Expand Down Expand Up @@ -383,15 +369,6 @@ const loadAttributes = function(block, state) {
if (state['enabled'] === false) {
block.setEnabled(false);
}
if (state['editable'] === false) {
block.setEditable(false);
}
if (state['deletable'] === false) {
block.setDeletable(false);
}
if (state['movable'] === false) {
block.setMovable(false);
}
if (state['inline'] !== undefined) {
block.setInputsInline(state['inline']);
}
Expand Down
64 changes: 0 additions & 64 deletions tests/mocha/jso_serialization_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,70 +83,6 @@ suite('JSO Serialization', function() {
});
});

suite('Deletable', function() {
test('False', function() {
const block = this.workspace.newBlock('row_block');
block.setDeletable(false);
const jso = Blockly.serialization.blocks.save(block);
assertProperty(jso, 'deletable', false);
});

test('True', function() {
const block = this.workspace.newBlock('row_block');
block.setDeletable(true);
const jso = Blockly.serialization.blocks.save(block);
assertNoProperty(jso, 'deletable');
});

test('False and Shadow', function() {
const block = this.workspace.newBlock('row_block');
block.setDeletable(false);
block.setShadow(true);
const jso = Blockly.serialization.blocks.save(block);
assertNoProperty(jso, 'deletable');
});
});

suite('Movable', function() {
test('False', function() {
const block = this.workspace.newBlock('row_block');
block.setMovable(false);
const jso = Blockly.serialization.blocks.save(block);
assertProperty(jso, 'movable', false);
});

test('True', function() {
const block = this.workspace.newBlock('row_block');
block.setMovable(true);
const jso = Blockly.serialization.blocks.save(block);
assertNoProperty(jso, 'movable');
});

test('False and Shadow', function() {
const block = this.workspace.newBlock('row_block');
block.setMovable(false);
block.setShadow(true);
const jso = Blockly.serialization.blocks.save(block);
assertNoProperty(jso, 'movable');
});
});

suite('Editable', function() {
test('False', function() {
const block = this.workspace.newBlock('row_block');
block.setEditable(false);
const jso = Blockly.serialization.blocks.save(block);
assertProperty(jso, 'editable', false);
});

test('True', function() {
const block = this.workspace.newBlock('row_block');
block.setEditable(true);
const jso = Blockly.serialization.blocks.save(block);
assertNoProperty(jso, 'editable');
});
});

suite('Inline', function() {
test('True', function() {
const block = this.workspace.newBlock('statement_block');
Expand Down
17 changes: 1 addition & 16 deletions tests/mocha/serializer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Serializer.Empty = new SerializerTestCase('Empty',
);
Serializer.Data = new SerializerTestCase('Data',
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="logic_negate" id="id******************" editable="false" x="42" y="42">' +
'<block type="logic_negate" id="id******************" x="42" y="42">' +
'<data>test data</data>' +
'</block>' +
'</xml>');
Expand All @@ -71,25 +71,10 @@ Serializer.Attributes.Disabled = new SerializerTestCase('Disabled',
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="logic_negate" id="id******************" disabled="true" x="42" y="42"></block>' +
'</xml>');
Serializer.Attributes.Deletable = new SerializerTestCase('Deletable',
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="logic_negate" id="id******************" deletable="false" x="42" y="42"></block>' +
'</xml>');
Serializer.Attributes.Movable = new SerializerTestCase('Movable',
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="logic_negate" id="id******************" movable="false" x="42" y="42"></block>' +
'</xml>');
Serializer.Attributes.Editable = new SerializerTestCase('Editable',
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="logic_negate" id="id******************" editable="false" x="42" y="42"></block>' +
'</xml>');
Serializer.Attributes.testCases = [
Serializer.Attributes.Basic,
Serializer.Attributes.Collapsed,
Serializer.Attributes.Disabled,
Serializer.Attributes.Deletable,
Serializer.Attributes.Movable,
Serializer.Attributes.Editable,
];

Serializer.Attributes.Inline = new SerializerTestSuite('Inline');
Expand Down

0 comments on commit 9aecac3

Please sign in to comment.