Skip to content

Commit

Permalink
chore: Remove blockly factory use of utils.dom.add/removeClass (googl…
Browse files Browse the repository at this point in the history
…e#6534)

* Remove usages of utils.dom.add/removeClass from Blockly Factory
* Use template strings for error messages.

(Random stuff found while working on something larger.)
  • Loading branch information
NeilFraser authored Oct 12, 2022
1 parent ab9825c commit 9b81317
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 326 deletions.
3 changes: 1 addition & 2 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ const PROCEDURE_DEF_COMMON = {
this.argumentVarModels_.push(variable);
} else {
console.log(
'Failed to create a variable with name ' + varName +
', ignoring.');
`Failed to create a variable named "${varName}", ignoring.`);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,8 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
}

/**
* Updates the color of the block (and children) to match the current disabled
* state.
* Updates the colour of the block (and children) to match the current
* disabled state.
*
* @internal
*/
Expand Down
21 changes: 8 additions & 13 deletions core/shortcut_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export class ShortcutRegistry {
register(shortcut: KeyboardShortcut, opt_allowOverrides?: boolean) {
const registeredShortcut = this.shortcuts.get(shortcut.name);
if (registeredShortcut && !opt_allowOverrides) {
throw new Error(
'Shortcut with name "' + shortcut.name + '" already exists.');
throw new Error(`Shortcut named "${shortcut.name}" already exists.`);
}
this.shortcuts.set(shortcut.name, shortcut);

Expand All @@ -81,8 +80,7 @@ export class ShortcutRegistry {
const shortcut = this.shortcuts.get(shortcutName);

if (!shortcut) {
console.warn(
'Keyboard shortcut with name "' + shortcutName + '" not found.');
console.warn(`Keyboard shortcut named "${shortcutName}" not found.`);
return false;
}

Expand Down Expand Up @@ -110,9 +108,8 @@ export class ShortcutRegistry {
keyCode = String(keyCode);
const shortcutNames = this.keyMap.get(keyCode);
if (shortcutNames && !opt_allowCollision) {
throw new Error(
'Shortcut with name "' + shortcutName + '" collides with shortcuts ' +
shortcutNames.toString());
throw new Error(`Shortcut named "${
shortcutName}" collides with shortcuts "${shortcutNames}"`);
} else if (shortcutNames && opt_allowCollision) {
shortcutNames.unshift(shortcutName);
} else {
Expand All @@ -138,9 +135,8 @@ export class ShortcutRegistry {

if (!shortcutNames) {
if (!opt_quiet) {
console.warn(
'No keyboard shortcut with name "' + shortcutName +
'" registered with key code "' + keyCode + '"');
console.warn(`No keyboard shortcut named "${
shortcutName}" registered with key code "${keyCode}"`);
}
return false;
}
Expand All @@ -154,9 +150,8 @@ export class ShortcutRegistry {
return true;
}
if (!opt_quiet) {
console.warn(
'No keyboard shortcut with name "' + shortcutName +
'" registered with key code "' + keyCode + '"');
console.warn(`No keyboard shortcut named "${
shortcutName}" registered with key code "${keyCode}"`);
}
return false;
}
Expand Down
33 changes: 20 additions & 13 deletions demos/blockfactory/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,25 @@ BlockFactory.updateBlocksFlagDelayed = false;
*/
BlockFactory.STARTER_BLOCK_XML_TEXT =
'<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="factory_base" deletable="false" movable="false">' +
'<value name="TOOLTIP">' +
'<block type="text" deletable="false" movable="false">' +
'<field name="TEXT"></field></block></value>' +
'<value name="HELPURL">' +
'<block type="text" deletable="false" movable="false">' +
'<field name="TEXT"></field></block></value>' +
'<value name="COLOUR">' +
'<block type="colour_hue">' +
'<mutation colour="#5b67a5"></mutation>' +
'<field name="HUE">230</field>' +
'</block></value></block></xml>';
'<block type="factory_base" deletable="false" movable="false">' +
'<value name="TOOLTIP">' +
'<block type="text" deletable="false" movable="false">' +
'<field name="TEXT"></field>' +
'</block>' +
'</value>' +
'<value name="HELPURL">' +
'<block type="text" deletable="false" movable="false">' +
'<field name="TEXT"></field>' +
'</block>' +
'</value>' +
'<value name="COLOUR">' +
'<block type="colour_hue">' +
'<mutation colour="#5b67a5"></mutation>' +
'<field name="HUE">230</field>' +
'</block>' +
'</value>' +
'</block>' +
'</xml>';

/**
* Change the language code format.
Expand Down Expand Up @@ -328,4 +335,4 @@ BlockFactory.manualEdit = function() {
BlockFactory.updateBlocksFlag = true;
BlockFactory.updateBlocksFlagDelayed = true;
BlockFactory.updateLanguage();
}
};
Loading

0 comments on commit 9b81317

Please sign in to comment.