Delete monitor block when variable is deleted

This commit is contained in:
DD 2017-11-15 11:34:20 -05:00
parent 95ca10038b
commit aa0064948a
3 changed files with 13 additions and 20 deletions

View file

@ -250,9 +250,7 @@ class Blocks {
if (optRuntime && this._blocks[e.blockId].topLevel) {
optRuntime.quietGlow(e.blockId);
}
this.deleteBlock({
id: e.blockId
});
this.deleteBlock(e.blockId);
break;
case 'var_create':
// New variables being created by the user are all global.
@ -414,37 +412,37 @@ class Blocks {
/**
* Block management: delete blocks and their associated scripts.
* @param {!object} e Blockly delete event to be processed.
* @param {!string} blockId Id of block to delete
*/
deleteBlock (e) {
deleteBlock (blockId) {
// @todo In runtime, stop threads running on this script.
// Get block
const block = this._blocks[e.id];
const block = this._blocks[blockId];
// Delete children
if (block.next !== null) {
this.deleteBlock({id: block.next});
this.deleteBlock(block.next);
}
// Delete inputs (including branches)
for (const input in block.inputs) {
// If it's null, the block in this input moved away.
if (block.inputs[input].block !== null) {
this.deleteBlock({id: block.inputs[input].block});
this.deleteBlock(block.inputs[input].block);
}
// Delete obscured shadow blocks.
if (block.inputs[input].shadow !== null &&
block.inputs[input].shadow !== block.inputs[input].block) {
this.deleteBlock({id: block.inputs[input].shadow});
this.deleteBlock(block.inputs[input].shadow);
}
}
// Delete any script starting with this block.
this._deleteScript(e.id);
this._deleteScript(blockId);
// Delete block itself.
delete this._blocks[e.id];
delete this._blocks[blockId];
}
// ---------------------------------------------------------------------

View file

@ -189,6 +189,7 @@ class Target extends EventEmitter {
if (this.variables.hasOwnProperty(id)) {
delete this.variables[id];
if (this.runtime) {
this.runtime.monitorBlocks.deleteBlock(id);
this.runtime.requestRemoveMonitor(id);
}
}

View file

@ -421,9 +421,7 @@ test('delete', t => {
inputs: {},
topLevel: true
});
b.deleteBlock({
id: 'foo'
});
b.deleteBlock('foo');
t.type(b._blocks.foo, 'undefined');
t.equal(b._scripts.indexOf('foo'), -1);
@ -458,9 +456,7 @@ test('delete chain', t => {
inputs: {},
topLevel: false
});
b.deleteBlock({
id: 'foo'
});
b.deleteBlock('foo');
t.type(b._blocks.foo, 'undefined');
t.type(b._blocks.foo2, 'undefined');
t.type(b._blocks.foo3, 'undefined');
@ -531,9 +527,7 @@ test('delete inputs', t => {
inputs: {},
topLevel: false
});
b.deleteBlock({
id: 'foo'
});
b.deleteBlock('foo');
t.type(b._blocks.foo, 'undefined');
t.type(b._blocks.foo2, 'undefined');
t.type(b._blocks.foo3, 'undefined');