mirror of
https://github.com/google/blockly.git
synced 2026-01-09 18:10:08 +01:00
Revert "feat!: allow blocks to receive their own delete events" (#6676)
This commit is contained in:
@@ -979,7 +979,7 @@ const PROCEDURE_CALL_COMMON = {
|
||||
Xml.domToWorkspace(xml, this.workspace);
|
||||
Events.setGroup(false);
|
||||
}
|
||||
} else if (event.type === Events.BLOCK_DELETE && event.blockId != this.id) {
|
||||
} else if (event.type === Events.BLOCK_DELETE) {
|
||||
// Look for the case where a procedure definition has been deleted,
|
||||
// leaving this block (a procedure call) orphaned. In this case, delete
|
||||
// the orphan.
|
||||
|
||||
@@ -324,16 +324,15 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
if (this.isDeadOrDying()) {
|
||||
return;
|
||||
}
|
||||
// Terminate onchange event calls.
|
||||
if (this.onchangeWrapper_) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
}
|
||||
|
||||
this.unplug(healStack);
|
||||
if (eventUtils.isEnabled()) {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_DELETE))(this));
|
||||
}
|
||||
|
||||
if (this.onchangeWrapper_) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
}
|
||||
|
||||
eventUtils.disable();
|
||||
|
||||
try {
|
||||
|
||||
@@ -11,6 +11,7 @@ import {assertCallBlockStructure, assertDefBlockStructure, createProcDefBlock, c
|
||||
import {runSerializationTestSuite} from '../test_helpers/serialization.js';
|
||||
import {createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} from '../test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Procedures', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
@@ -1209,43 +1210,3 @@ suite('Procedures', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Procedures, dont auto fire events', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this, {fireEventsNow: false});
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
const testSuites = [
|
||||
{title: 'procedures_defreturn', hasReturn: true,
|
||||
defType: 'procedures_defreturn', callType: 'procedures_callreturn'},
|
||||
{title: 'procedures_defnoreturn', hasReturn: false,
|
||||
defType: 'procedures_defnoreturn', callType: 'procedures_callnoreturn'},
|
||||
];
|
||||
|
||||
testSuites.forEach((testSuite) => {
|
||||
suite(testSuite.title, function() {
|
||||
suite('Disposal', function() {
|
||||
test('callers are disposed when definitions are disposed', function() {
|
||||
this.defBlock = new Blockly.Block(this.workspace, testSuite.defType);
|
||||
this.defBlock.setFieldValue('proc name', 'NAME');
|
||||
this.callerBlock = new Blockly.Block(
|
||||
this.workspace, testSuite.callType);
|
||||
this.callerBlock.setFieldValue('proc name', 'NAME');
|
||||
|
||||
// Run the clock now so that the create events get fired. If we fire
|
||||
// it after disposing, a new procedure def will get created when
|
||||
// the caller create event is heard.
|
||||
this.clock.runAll();
|
||||
this.defBlock.dispose();
|
||||
this.clock.runAll();
|
||||
|
||||
chai.assert.isTrue(this.callerBlock.disposed);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,24 +21,6 @@ suite('Block Delete Event', function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Receiving', function() {
|
||||
test('blocks receive their own delete events', function() {
|
||||
Blockly.Blocks['test'] = {
|
||||
onchange: function(e) {},
|
||||
};
|
||||
// Need to stub the definition, because the property on the definition is
|
||||
// what gets registered as an event listener.
|
||||
const spy = sinon.spy(Blockly.Blocks['test'], 'onchange');
|
||||
const testBlock = this.workspace.newBlock('test');
|
||||
|
||||
testBlock.dispose();
|
||||
|
||||
const deleteClass = eventUtils.get(eventUtils.BLOCK_DELETE);
|
||||
chai.assert.isTrue(spy.calledOnce);
|
||||
chai.assert.isTrue(spy.getCall(0).args[0] instanceof deleteClass);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block = this.workspace.newBlock('row_block', 'block_id');
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
<div id="failureCount" style="display:none" tests_failed="unset"></div>
|
||||
<div id="failureMessages" style="display:none"></div>
|
||||
<!-- Load mocha et al. before bootstrapping so that we can safely
|
||||
goog.require() the test modules that make calls to (e.g.)
|
||||
suite() at the top level. -->
|
||||
goog.require() the test modules that make calls to (e.g.)
|
||||
suite() at the top level. -->
|
||||
<script src="../../node_modules/chai/chai.js"></script>
|
||||
<script src="../../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../../node_modules/sinon/pkg/sinon.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user