fix: dispose performance (#6894)

* fix: improve dispose performance

* chore: cleanup dispose functions

* chore: split dispose into dispose and disposeInternal

* chore: remove unnecessary node removal

* fix: remove unnecessary unbinding of event listeners

* fix: readd skipping event construction

* chore: work on fixing tests

* chore: fix remaining test failures

* chore: format

* chore: typo

* fix: first pass of PR comments

* chore: remove TODO
This commit is contained in:
Beka Westberg
2023-03-16 15:28:25 -07:00
committed by GitHub
parent c2919c51bd
commit 670f7da802
10 changed files with 82 additions and 76 deletions

View File

@@ -386,7 +386,7 @@ suite('Connection checker', function() {
});
test('Connect to unconnected unmovable block', function() {
// Delete blockA.
this.blockB.previousConnection.disconnect();
this.blockA.dispose();
// Try to connect blockC above blockB.
@@ -436,7 +436,7 @@ suite('Connection checker', function() {
});
test('Connect to unconnected unmovable block', function() {
// Delete blockA
this.blockB.outputConnection.disconnect();
this.blockA.dispose();
// Try to connect C's input to B's output. Allowed because B is now unconnected.

View File

@@ -6,13 +6,12 @@
goog.declareModuleId('Blockly.test.eventBlockDelete');
import * as eventUtils from '../../build/src/core/events/utils.js';
import {defineRowBlock} from './test_helpers/block_definitions.js';
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
suite('Block Delete Event', function() {
setup(function() {
sharedTestSetup.call(this);
this.clock = sharedTestSetup.call(this, {fireEventsNow: false}).clock;
defineRowBlock();
this.workspace = new Blockly.Workspace();
});
@@ -21,6 +20,23 @@ suite('Block Delete Event', function() {
sharedTestTeardown.call(this);
});
suite('Receiving', function() {
test('blocks do not 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();
this.clock.runAll();
chai.assert.isFalse(spy.called);
});
});
suite('Serialization', function() {
test('events round-trip through JSON', function() {
const block = this.workspace.newBlock('row_block', 'block_id');

View File

@@ -1866,7 +1866,7 @@ const runSerializerTestSuite = (serializer, deserializer, testSuite) => {
suiteCall(testSuite.title, function() {
setup(function() {
sharedTestSetup.call(this);
sharedTestSetup.call(this, {fireEventsNow: false});
this.workspace = new Blockly.Workspace();
});