From 619ee66b23967b26b5a25225a640be7915a741c7 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 22 Apr 2022 09:43:07 -0700 Subject: [PATCH] fix: add compose and decompose to block (#6102) --- core/block.js | 14 ++++++++++++++ core/events/utils.js | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/block.js b/core/block.js index ce8f274b6..a56556e20 100644 --- a/core/block.js +++ b/core/block.js @@ -179,6 +179,20 @@ class Block { */ this.getDeveloperVariables = undefined; + /** + * An optional function that reconfigures the block based on the contents of + * the mutator dialog. + * @type {undefined|?function(!Block):void} + */ + this.compose = undefined; + + /** + * An optional function that populates the mutator's dialog with + * this block's components. + * @type {undefined|?function(!Workspace):!Block} + */ + this.decompose = undefined; + /** @type {string} */ this.id = (opt_id && !workspace.getBlockById(opt_id)) ? opt_id : diff --git a/core/events/utils.js b/core/events/utils.js index dfd2d4f06..98d65be60 100644 --- a/core/events/utils.js +++ b/core/events/utils.js @@ -372,8 +372,8 @@ const filter = function(queueIn, forward) { if (!event.isNull()) { // Treat all UI events as the same type in hash table. const eventType = event.isUiEvent ? UI : event.type; - // TODO(#5927): Ceck whether `blockId` exists before accessing it. - const blockId = /** @type {*} */ (event).blockId; + // TODO(#5927): Check whether `blockId` exists before accessing it. + const blockId = /** @type {?} */ (event).blockId; const key = [eventType, blockId, event.workspaceId].join(' '); const lastEntry = hash[key]; @@ -525,7 +525,7 @@ exports.getDescendantIds = getDescendantIds; * @alias Blockly.Events.utils.fromJson */ const fromJson = function(json, workspace) { - const eventClass = get(json.type); + const eventClass = get(json['type']); if (!eventClass) { throw Error('Unknown event type.'); }