From 2b1f33cc7b2c633ae841b68bc3c68247fad335ec Mon Sep 17 00:00:00 2001 From: Aaron Imming Date: Fri, 8 Oct 2021 01:15:00 +0800 Subject: [PATCH] feat: add Blockly.Extensions.isRegistered function (#5500) Co-authored-by: Monica Kozbial <6621618+moniika@users.noreply.github.com> --- core/extensions.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/extensions.js b/core/extensions.js index 426de3f6be2..6fa9c64a75a 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -127,7 +127,7 @@ exports.registerMutator = registerMutator; * @alias Blockly.Extensions.unregister */ const unregister = function(name) { - if (allExtensions[name]) { + if (isRegistered(name)) { delete allExtensions[name]; } else { console.warn( @@ -136,6 +136,18 @@ const unregister = function(name) { }; exports.unregister = unregister; +/** + * Returns whether an extension is registered with the given name. + * @param {string} name The name of the extension to check for. + * @return {boolean} True if the extension is registered. False if it is + * not registered. + * @alias Blockly.Extensions.isRegistered + */ +const isRegistered = function(name) { + return !!allExtensions[name]; +}; +exports.isRegistered = isRegistered; + /** * Applies an extension method to a block. This should only be called during * block construction.