mirror of
https://github.com/google/blockly.git
synced 2026-01-09 18:10:08 +01:00
fix!: move destroy earlier in the lifcycle (#7117)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user