fix!: move destroy earlier in the lifcycle (#7117)

This commit is contained in:
Beka Westberg
2023-06-01 05:25:31 -07:00
committed by GitHub
parent 6bae8a4b92
commit 91be84ab7c
2 changed files with 35 additions and 17 deletions

View File

@@ -343,23 +343,17 @@ export class Block implements IASTNodeLocation, IDeletable {
this.workspace.removeChangeListener(this.onchangeWrapper_);
}
eventUtils.disable();
try {
this.workspace.removeTypedBlock(this);
this.workspace.removeBlockById(this.id);
this.disposing = true;
this.workspace.removeTypedBlock(this);
this.workspace.removeBlockById(this.id);
this.disposing = true;
this.childBlocks_.forEach((c) => c.disposeInternal());
this.inputList.forEach((i) => i.dispose());
this.inputList.length = 0;
this.getConnections_(true).forEach((c) => c.dispose());
} finally {
eventUtils.enable();
if (typeof this.destroy === 'function') {
this.destroy();
}
this.disposed = true;
}
if (typeof this.destroy === 'function') this.destroy();
this.childBlocks_.forEach((c) => c.disposeInternal());
this.inputList.forEach((i) => i.dispose());
this.inputList.length = 0;
this.getConnections_(true).forEach((c) => c.dispose());
this.disposed = true;
}
/**

View File

@@ -213,7 +213,11 @@ suite('Blocks', function () {
suite('calling destroy', function () {
setup(function () {
Blockly.Blocks['destroyable_block'] = {
init: function () {},
init: function () {
this.appendStatementInput('STATEMENT');
this.setPreviousStatement(true);
this.setNextStatement(true);
},
destroy: function () {},
};
this.block = this.workspace.newBlock('destroyable_block');
@@ -274,6 +278,26 @@ suite('Blocks', function () {
'Expected to be able to fire events from destroy'
);
});
test('child blocks can fire events from destroy', function () {
const mockEvent = createMockEvent(this.workspace);
const childBlock = this.workspace.newBlock('destroyable_block');
this.block
.getInput('STATEMENT')
.connection.connect(childBlock.previousConnection);
childBlock.destroy = function () {
Blockly.Events.fire(mockEvent);
};
const spy = createChangeListenerSpy(this.workspace);
this.block.dispose();
this.clock.runAll();
chai.assert.isTrue(
spy.calledWith(mockEvent),
'Expected to be able to fire events from destroy'
);
});
});
suite('stack/row healing', function () {