mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
This reverts commit 485bd4dddf.
This commit is contained in:
@@ -20,7 +20,6 @@ import './events/events_block_create.js';
|
||||
import './events/events_block_delete.js';
|
||||
|
||||
import {Blocks} from './blocks.js';
|
||||
import {BlockDelete} from './events/events_block_delete.js';
|
||||
import type {Comment} from './comment.js';
|
||||
import * as common from './common.js';
|
||||
import {Connection} from './connection.js';
|
||||
@@ -331,6 +330,10 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_DELETE))(this));
|
||||
}
|
||||
|
||||
if (this.onchangeWrapper_) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
}
|
||||
|
||||
eventUtils.disable();
|
||||
|
||||
try {
|
||||
@@ -1024,13 +1027,7 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
}
|
||||
this.onchange = onchangeFn;
|
||||
this.onchangeWrapper_ = (e) => {
|
||||
onchangeFn.call(this, e);
|
||||
if (e.type === eventUtils.BLOCK_DELETE &&
|
||||
(e as BlockDelete).blockId === this.id) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_!);
|
||||
}
|
||||
};
|
||||
this.onchangeWrapper_ = onchangeFn.bind(this);
|
||||
this.workspace.addChangeListener(this.onchangeWrapper_);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown
|
||||
|
||||
suite('Block Delete Event', function() {
|
||||
setup(function() {
|
||||
const {clock} = sharedTestSetup.call(this, {fireEventsNow: false});
|
||||
this.clock = clock;
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
@@ -23,9 +22,9 @@ suite('Block Delete Event', function() {
|
||||
});
|
||||
|
||||
suite('Receiving', function() {
|
||||
test('blocks receive their own delete events', function(done) {
|
||||
test('blocks receive their own delete events', function() {
|
||||
Blockly.Blocks['test'] = {
|
||||
onchange: function(e) { },
|
||||
onchange: function(e) {},
|
||||
};
|
||||
// Need to stub the definition, because the property on the definition is
|
||||
// what gets registered as an event listener.
|
||||
@@ -33,13 +32,10 @@ suite('Block Delete Event', function() {
|
||||
const testBlock = this.workspace.newBlock('test');
|
||||
|
||||
testBlock.dispose();
|
||||
this.clock.tick(2); // Fire events. The built-in timeout is 0.
|
||||
|
||||
const deleteClass = eventUtils.get(eventUtils.BLOCK_DELETE);
|
||||
chai.assert.isTrue(
|
||||
spy.calledWith(sinon.match.instanceOf(deleteClass)),
|
||||
'Expected the block to receive its own delete event.');
|
||||
done();
|
||||
chai.assert.isTrue(spy.calledOnce);
|
||||
chai.assert.isTrue(spy.getCall(0).args[0] instanceof deleteClass);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -105,8 +105,6 @@ function wrapDefineBlocksWithJsonArrayWithCleanup_(sharedCleanupObj) {
|
||||
*
|
||||
* @param {Object<string, boolean>} options Options to enable/disable setup
|
||||
* of certain stubs.
|
||||
* @return {{clock: *}} The fake clock (as part of an object to make refactoring
|
||||
* easier).
|
||||
*/
|
||||
export function sharedTestSetup(options = {}) {
|
||||
this.sharedSetupCalled_ = true;
|
||||
@@ -124,9 +122,6 @@ export function sharedTestSetup(options = {}) {
|
||||
this.blockTypesCleanup_ = this.sharedCleanup.blockTypesCleanup_;
|
||||
this.messagesCleanup_ = this.sharedCleanup.messagesCleanup_;
|
||||
wrapDefineBlocksWithJsonArrayWithCleanup_(this.sharedCleanup);
|
||||
return {
|
||||
clock: this.clock,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user