diff --git a/src/engine/runtime.js b/src/engine/runtime.js index b5739579c..310d9e77b 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -787,11 +787,9 @@ class Runtime extends EventEmitter { this._fillExtensionCategory(categoryInfo, extensionInfo); - const fieldTypeDefinitionsForScratch = []; for (const fieldTypeName in categoryInfo.customFieldTypes) { if (extensionInfo.customFieldTypes.hasOwnProperty(fieldTypeName)) { const fieldTypeInfo = categoryInfo.customFieldTypes[fieldTypeName]; - fieldTypeDefinitionsForScratch.push(fieldTypeInfo.scratchBlocksDefinition); // Emit events for custom field types from extension this.emit(Runtime.EXTENSION_FIELD_ADDED, { @@ -801,9 +799,7 @@ class Runtime extends EventEmitter { } } - const allBlocks = fieldTypeDefinitionsForScratch.concat(categoryInfo.blocks).concat(categoryInfo.menus); - - this.emit(Runtime.EXTENSION_ADDED, allBlocks); + this.emit(Runtime.EXTENSION_ADDED, categoryInfo); } /** @@ -812,18 +808,16 @@ class Runtime extends EventEmitter { * @private */ _refreshExtensionPrimitives (extensionInfo) { - let extensionBlocks = []; for (const categoryInfo of this._blockInfo) { if (extensionInfo.id === categoryInfo.id) { categoryInfo.name = maybeFormatMessage(extensionInfo.name); categoryInfo.blocks = []; categoryInfo.menus = []; this._fillExtensionCategory(categoryInfo, extensionInfo); - extensionBlocks = extensionBlocks.concat(categoryInfo.blocks, categoryInfo.menus); + + this.emit(Runtime.BLOCKSINFO_UPDATE, categoryInfo); } } - - this.emit(Runtime.BLOCKSINFO_UPDATE, extensionBlocks); } /** diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 3320238f4..f383c0b0f 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -109,14 +109,14 @@ class VirtualMachine extends EventEmitter { this.runtime.on(Runtime.BLOCK_DRAG_END, (blocks, topBlockId) => { this.emit(Runtime.BLOCK_DRAG_END, blocks, topBlockId); }); - this.runtime.on(Runtime.EXTENSION_ADDED, blocksInfo => { - this.emit(Runtime.EXTENSION_ADDED, blocksInfo); + this.runtime.on(Runtime.EXTENSION_ADDED, categoryInfo => { + this.emit(Runtime.EXTENSION_ADDED, categoryInfo); }); this.runtime.on(Runtime.EXTENSION_FIELD_ADDED, (fieldName, fieldImplementation) => { this.emit(Runtime.EXTENSION_FIELD_ADDED, fieldName, fieldImplementation); }); - this.runtime.on(Runtime.BLOCKSINFO_UPDATE, blocksInfo => { - this.emit(Runtime.BLOCKSINFO_UPDATE, blocksInfo); + this.runtime.on(Runtime.BLOCKSINFO_UPDATE, categoryInfo => { + this.emit(Runtime.BLOCKSINFO_UPDATE, categoryInfo); }); this.runtime.on(Runtime.BLOCKS_NEED_UPDATE, () => { this.emitWorkspaceUpdate(); diff --git a/test/unit/extension_conversion.js b/test/unit/extension_conversion.js index 3a59c0a01..001130a32 100644 --- a/test/unit/extension_conversion.js +++ b/test/unit/extension_conversion.js @@ -160,7 +160,8 @@ const testLoop = function (t, loop) { test('registerExtensionPrimitives', t => { const runtime = new Runtime(); - runtime.on(Runtime.EXTENSION_ADDED, blocksInfo => { + runtime.on(Runtime.EXTENSION_ADDED, categoryInfo => { + const blocksInfo = categoryInfo.blocks; t.equal(blocksInfo.length, testExtensionInfo.blocks.length); blocksInfo.forEach(blockInfo => {