diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 92a2d58e7..11208bea9 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -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]; } // --------------------------------------------------------------------- diff --git a/src/engine/target.js b/src/engine/target.js index 2a6be81a6..b94c221bc 100644 --- a/src/engine/target.js +++ b/src/engine/target.js @@ -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); } } diff --git a/test/unit/engine_blocks.js b/test/unit/engine_blocks.js index 1055cda68..4353fe476 100644 --- a/test/unit/engine_blocks.js +++ b/test/unit/engine_blocks.js @@ -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');