Skip to content
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

Revert "feat!: allow blocks to receive their own delete events" #6676

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
41 changes: 1 addition & 40 deletions tests/mocha/blocks/procedures_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});
});
});
});
18 changes: 0 additions & 18 deletions tests/mocha/event_block_delete_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions tests/mocha/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down