Skip to content

Commit

Permalink
refactor: Rename export of Blockly.blocks to Blocks
Browse files Browse the repository at this point in the history
This effectively finishes undoing most of the work done by earlier
commits in this PR.
  • Loading branch information
cpcallen committed Sep 22, 2021
1 parent 6261cf2 commit 133d78c
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 93 deletions.
19 changes: 9 additions & 10 deletions blocks/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
goog.provide('Blockly.Constants.Lists');

goog.require('Blockly');
goog.require('Blockly.blocks');
goog.require('Blockly.FieldDropdown');
goog.require('Blockly.FieldLabel');
goog.require('Blockly.Mutator');
Expand Down Expand Up @@ -115,7 +114,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
}
]); // END JSON EXTRACT (Do not delete this comment.)

Blockly.blocks['lists_create_with'] = {
Blockly.Blocks['lists_create_with'] = {
/**
* Block for creating a list with any number of elements of any type.
* @this {Blockly.Block}
Expand Down Expand Up @@ -259,7 +258,7 @@ Blockly.blocks['lists_create_with'] = {
}
};

Blockly.blocks['lists_create_with_container'] = {
Blockly.Blocks['lists_create_with_container'] = {
/**
* Mutator block for list container.
* @this {Blockly.Block}
Expand All @@ -274,7 +273,7 @@ Blockly.blocks['lists_create_with_container'] = {
}
};

Blockly.blocks['lists_create_with_item'] = {
Blockly.Blocks['lists_create_with_item'] = {
/**
* Mutator block for adding items.
* @this {Blockly.Block}
Expand All @@ -290,7 +289,7 @@ Blockly.blocks['lists_create_with_item'] = {
}
};

Blockly.blocks['lists_indexOf'] = {
Blockly.Blocks['lists_indexOf'] = {
/**
* Block for finding an item in the list.
* @this {Blockly.Block}
Expand Down Expand Up @@ -319,7 +318,7 @@ Blockly.blocks['lists_indexOf'] = {
}
};

Blockly.blocks['lists_getIndex'] = {
Blockly.Blocks['lists_getIndex'] = {
/**
* Block for getting element at index.
* @this {Blockly.Block}
Expand Down Expand Up @@ -510,7 +509,7 @@ Blockly.blocks['lists_getIndex'] = {
}
};

Blockly.blocks['lists_setIndex'] = {
Blockly.Blocks['lists_setIndex'] = {
/**
* Block for setting the element at index.
* @this {Blockly.Block}
Expand Down Expand Up @@ -656,7 +655,7 @@ Blockly.blocks['lists_setIndex'] = {
}
};

Blockly.blocks['lists_getSublist'] = {
Blockly.Blocks['lists_getSublist'] = {
/**
* Block for getting sublist.
* @this {Blockly.Block}
Expand Down Expand Up @@ -772,7 +771,7 @@ Blockly.blocks['lists_getSublist'] = {
}
};

Blockly.blocks['lists_sort'] = {
Blockly.Blocks['lists_sort'] = {
/**
* Block for sorting a list.
* @this {Blockly.Block}
Expand Down Expand Up @@ -812,7 +811,7 @@ Blockly.blocks['lists_sort'] = {
}
};

Blockly.blocks['lists_split'] = {
Blockly.Blocks['lists_split'] = {
/**
* Block for splitting text into a list, or joining a list into text.
* @this {Blockly.Block}
Expand Down
67 changes: 34 additions & 33 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
goog.provide('Blockly.blocks.procedures');

goog.require('Blockly');
goog.require('Blockly.blocks');
goog.require('Blockly.Comment');
goog.require('Blockly.FieldCheckbox');
goog.require('Blockly.FieldLabel');
Expand All @@ -22,7 +21,7 @@ goog.require('Blockly.Mutator');
goog.require('Blockly.Warning');


Blockly.blocks['procedures_defnoreturn'] = {
Blockly.Blocks['procedures_defnoreturn'] = {
/**
* Block for defining a procedure with no return value.
* @this {Blockly.Block}
Expand Down Expand Up @@ -450,7 +449,7 @@ Blockly.blocks['procedures_defnoreturn'] = {
callType_: 'procedures_callnoreturn'
};

Blockly.blocks['procedures_defreturn'] = {
Blockly.Blocks['procedures_defreturn'] = {
/**
* Block for defining a procedure with a return value.
* @this {Blockly.Block}
Expand Down Expand Up @@ -482,12 +481,14 @@ Blockly.blocks['procedures_defreturn'] = {
this.setStatements_(true);
this.statementConnection_ = null;
},
setStatements_: Blockly.blocks['procedures_defnoreturn'].setStatements_,
updateParams_: Blockly.blocks['procedures_defnoreturn'].updateParams_,
mutationToDom: Blockly.blocks['procedures_defnoreturn'].mutationToDom,
domToMutation: Blockly.blocks['procedures_defnoreturn'].domToMutation,
decompose: Blockly.blocks['procedures_defnoreturn'].decompose,
compose: Blockly.blocks['procedures_defnoreturn'].compose,
setStatements_: Blockly.Blocks['procedures_defnoreturn'].setStatements_,
updateParams_: Blockly.Blocks['procedures_defnoreturn'].updateParams_,
mutationToDom: Blockly.Blocks['procedures_defnoreturn'].mutationToDom,
domToMutation: Blockly.Blocks['procedures_defnoreturn'].domToMutation,
saveExtraState: Blockly.Blocks['procedures_defnoreturn'].saveExtraState,
loadExtraState: Blockly.Blocks['procedures_defnoreturn'].loadExtraState,
decompose: Blockly.Blocks['procedures_defnoreturn'].decompose,
compose: Blockly.Blocks['procedures_defnoreturn'].compose,
/**
* Return the signature of this procedure definition.
* @return {!Array} Tuple containing three elements:
Expand All @@ -499,16 +500,16 @@ Blockly.blocks['procedures_defreturn'] = {
getProcedureDef: function() {
return [this.getFieldValue('NAME'), this.arguments_, true];
},
getVars: Blockly.blocks['procedures_defnoreturn'].getVars,
getVarModels: Blockly.blocks['procedures_defnoreturn'].getVarModels,
renameVarById: Blockly.blocks['procedures_defnoreturn'].renameVarById,
updateVarName: Blockly.blocks['procedures_defnoreturn'].updateVarName,
displayRenamedVar_: Blockly.blocks['procedures_defnoreturn'].displayRenamedVar_,
customContextMenu: Blockly.blocks['procedures_defnoreturn'].customContextMenu,
getVars: Blockly.Blocks['procedures_defnoreturn'].getVars,
getVarModels: Blockly.Blocks['procedures_defnoreturn'].getVarModels,
renameVarById: Blockly.Blocks['procedures_defnoreturn'].renameVarById,
updateVarName: Blockly.Blocks['procedures_defnoreturn'].updateVarName,
displayRenamedVar_: Blockly.Blocks['procedures_defnoreturn'].displayRenamedVar_,
customContextMenu: Blockly.Blocks['procedures_defnoreturn'].customContextMenu,
callType_: 'procedures_callreturn'
};

Blockly.blocks['procedures_mutatorcontainer'] = {
Blockly.Blocks['procedures_mutatorcontainer'] = {
/**
* Mutator block for procedure container.
* @this {Blockly.Block}
Expand All @@ -526,7 +527,7 @@ Blockly.blocks['procedures_mutatorcontainer'] = {
},
};

Blockly.blocks['procedures_mutatorarg'] = {
Blockly.Blocks['procedures_mutatorarg'] = {
/**
* Mutator block for procedure argument.
* @this {Blockly.Block}
Expand Down Expand Up @@ -637,7 +638,7 @@ Blockly.blocks['procedures_mutatorarg'] = {
}
};

Blockly.blocks['procedures_callnoreturn'] = {
Blockly.Blocks['procedures_callnoreturn'] = {
/**
* Block for calling a procedure with no return value.
* @this {Blockly.Block}
Expand Down Expand Up @@ -1029,7 +1030,7 @@ Blockly.blocks['procedures_callnoreturn'] = {
defType_: 'procedures_defnoreturn'
};

Blockly.blocks['procedures_callreturn'] = {
Blockly.Blocks['procedures_callreturn'] = {
/**
* Block for calling a procedure with a return value.
* @this {Blockly.Block}
Expand All @@ -1048,24 +1049,24 @@ Blockly.blocks['procedures_callreturn'] = {
this.previousEnabledState_ = true;
},

getProcedureCall: Blockly.blocks['procedures_callnoreturn'].getProcedureCall,
renameProcedure: Blockly.blocks['procedures_callnoreturn'].renameProcedure,
getProcedureCall: Blockly.Blocks['procedures_callnoreturn'].getProcedureCall,
renameProcedure: Blockly.Blocks['procedures_callnoreturn'].renameProcedure,
setProcedureParameters_:
Blockly.blocks['procedures_callnoreturn'].setProcedureParameters_,
updateShape_: Blockly.blocks['procedures_callnoreturn'].updateShape_,
mutationToDom: Blockly.blocks['procedures_callnoreturn'].mutationToDom,
domToMutation: Blockly.blocks['procedures_callnoreturn'].domToMutation,
saveExtraState: Blockly.blocks['procedures_callnoreturn'].saveExtraState,
loadExtraState: Blockly.blocks['procedures_callnoreturn'].loadExtraState,
getVars: Blockly.blocks['procedures_callnoreturn'].getVars,
getVarModels: Blockly.blocks['procedures_callnoreturn'].getVarModels,
onchange: Blockly.blocks['procedures_callnoreturn'].onchange,
Blockly.Blocks['procedures_callnoreturn'].setProcedureParameters_,
updateShape_: Blockly.Blocks['procedures_callnoreturn'].updateShape_,
mutationToDom: Blockly.Blocks['procedures_callnoreturn'].mutationToDom,
domToMutation: Blockly.Blocks['procedures_callnoreturn'].domToMutation,
saveExtraState: Blockly.Blocks['procedures_callnoreturn'].saveExtraState,
loadExtraState: Blockly.Blocks['procedures_callnoreturn'].loadExtraState,
getVars: Blockly.Blocks['procedures_callnoreturn'].getVars,
getVarModels: Blockly.Blocks['procedures_callnoreturn'].getVarModels,
onchange: Blockly.Blocks['procedures_callnoreturn'].onchange,
customContextMenu:
Blockly.blocks['procedures_callnoreturn'].customContextMenu,
Blockly.Blocks['procedures_callnoreturn'].customContextMenu,
defType_: 'procedures_defreturn'
};

Blockly.blocks['procedures_ifreturn'] = {
Blockly.Blocks['procedures_ifreturn'] = {
/**
* Block for conditionally returning a value from a procedure.
* @this {Blockly.Block}
Expand Down Expand Up @@ -1162,7 +1163,7 @@ Blockly.blocks['procedures_ifreturn'] = {
/**
* List of block types that are functions and thus do not need warnings.
* To add a new function type add this to your code:
* Blockly.blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
* Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
*/
FUNCTION_TYPES: ['procedures_defnoreturn', 'procedures_defreturn']
};
25 changes: 12 additions & 13 deletions blocks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ goog.provide('Blockly.blocks.texts'); // Deprecated
goog.provide('Blockly.Constants.Text');

goog.require('Blockly');
goog.require('Blockly.blocks');
goog.require('Blockly.FieldDropdown');
goog.require('Blockly.FieldImage');
goog.require('Blockly.FieldMultilineInput');
Expand Down Expand Up @@ -226,7 +225,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
}
]); // END JSON EXTRACT (Do not delete this comment.)

Blockly.blocks['text_getSubstring'] = {
Blockly.Blocks['text_getSubstring'] = {
/**
* Block for getting substring.
* @this {Blockly.Block}
Expand Down Expand Up @@ -347,7 +346,7 @@ Blockly.blocks['text_getSubstring'] = {
}
};

Blockly.blocks['text_changeCase'] = {
Blockly.Blocks['text_changeCase'] = {
/**
* Block for changing capitalization.
* @this {Blockly.Block}
Expand All @@ -368,7 +367,7 @@ Blockly.blocks['text_changeCase'] = {
}
};

Blockly.blocks['text_trim'] = {
Blockly.Blocks['text_trim'] = {
/**
* Block for trimming spaces.
* @this {Blockly.Block}
Expand All @@ -389,7 +388,7 @@ Blockly.blocks['text_trim'] = {
}
};

Blockly.blocks['text_print'] = {
Blockly.Blocks['text_print'] = {
/**
* Block for print statement.
* @this {Blockly.Block}
Expand All @@ -412,7 +411,7 @@ Blockly.blocks['text_print'] = {
}
};

Blockly.blocks['text_prompt_ext'] = {
Blockly.Blocks['text_prompt_ext'] = {
/**
* Block for prompt function (external message).
* @this {Blockly.Block}
Expand Down Expand Up @@ -474,7 +473,7 @@ Blockly.blocks['text_prompt_ext'] = {
// XML hooks are kept for backwards compatibility.
};

Blockly.blocks['text_prompt'] = {
Blockly.Blocks['text_prompt'] = {
/**
* Block for prompt function (internal message).
* The 'text_prompt_ext' block is preferred as it is more flexible.
Expand Down Expand Up @@ -506,12 +505,12 @@ Blockly.blocks['text_prompt'] = {
Blockly.Msg['TEXT_PROMPT_TOOLTIP_NUMBER'];
});
},
updateType_: Blockly.blocks['text_prompt_ext'].updateType_,
mutationToDom: Blockly.blocks['text_prompt_ext'].mutationToDom,
domToMutation: Blockly.blocks['text_prompt_ext'].domToMutation
updateType_: Blockly.Blocks['text_prompt_ext'].updateType_,
mutationToDom: Blockly.Blocks['text_prompt_ext'].mutationToDom,
domToMutation: Blockly.Blocks['text_prompt_ext'].domToMutation
};

Blockly.blocks['text_count'] = {
Blockly.Blocks['text_count'] = {
/**
* Block for counting how many times one string appears within another string.
* @this {Blockly.Block}
Expand Down Expand Up @@ -540,7 +539,7 @@ Blockly.blocks['text_count'] = {
}
};

Blockly.blocks['text_replace'] = {
Blockly.Blocks['text_replace'] = {
/**
* Block for replacing one string with another in the text.
* @this {Blockly.Block}
Expand Down Expand Up @@ -574,7 +573,7 @@ Blockly.blocks['text_replace'] = {
}
};

Blockly.blocks['text_reverse'] = {
Blockly.Blocks['text_reverse'] = {
/**
* Block for reversing a string.
* @this {Blockly.Block}
Expand Down
4 changes: 2 additions & 2 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ goog.module('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
const Abstract = goog.requireType('Blockly.Events.Abstract');
const ASTNode = goog.require('Blockly.ASTNode');
const {Blocks} = goog.require('Blockly.blocks');
/* eslint-disable-next-line no-unused-vars */
const Comment = goog.requireType('Blockly.Comment');
const Connection = goog.require('Blockly.Connection');
Expand All @@ -36,7 +37,6 @@ const Tooltip = goog.require('Blockly.Tooltip');
const VariableModel = goog.requireType('Blockly.VariableModel');
/* eslint-disable-next-line no-unused-vars */
const Workspace = goog.requireType('Blockly.Workspace');
const blocks = goog.require('Blockly.blocks');
const common = goog.require('Blockly.common');
const connectionTypes = goog.require('Blockly.connectionTypes');
const constants = goog.require('Blockly.constants');
Expand Down Expand Up @@ -208,7 +208,7 @@ const Block = function(workspace, prototypeName, opt_id) {
if (prototypeName) {
/** @type {string} */
this.type = prototypeName;
const prototype = blocks.definitions[prototypeName];
const prototype = Blocks[prototypeName];
if (!prototype || typeof prototype != 'object') {
throw TypeError('Unknown block type: ' + prototypeName);
}
Expand Down
10 changes: 4 additions & 6 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ const Block = goog.require('Blockly.Block');
const BlockDragger = goog.require('Blockly.BlockDragger');
const BlockDragSurfaceSvg = goog.require('Blockly.BlockDragSurfaceSvg');
const BlockSvg = goog.require('Blockly.BlockSvg');
const {Blocks} = goog.require('Blockly.blocks');
/* eslint-disable-next-line no-unused-vars */
const ICopyable = goog.requireType('Blockly.ICopyable');
const Size = goog.require('Blockly.utils.Size');
/* eslint-disable-next-line no-unused-vars */
const Workspace = goog.requireType('Blockly.Workspace');
/* eslint-disable-next-line no-unused-vars */
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
const blocks = goog.require('Blockly.blocks');
const browserEvents = goog.require('Blockly.browserEvents');
const clipboard = goog.require('Blockly.clipboard');
const colour = goog.require('Blockly.utils.colour');
Expand Down Expand Up @@ -63,9 +63,7 @@ goog.require('Blockly.Xml');


// Reexports.
exports.blocks = blocks.definitions;
/** @deprecated Use Blockly.blocks.definitions instead. */
exports.Blocks = blocks.definitions;
exports.Blocks = Blocks;

/**
* Blockly core version.
Expand Down Expand Up @@ -247,12 +245,12 @@ const defineBlocksWithJsonArray = function(jsonArray) {
'Block definition #' + i +
' in JSON array is missing a type attribute. Skipping.');
} else {
if (blocks.definitions[typename]) {
if (Blocks[typename]) {
console.warn(
'Block definition #' + i + ' in JSON array' +
' overwrites prior definition of "' + typename + '".');
}
blocks.definitions[typename] = {init: jsonInitFactory(elem)};
Blocks[typename] = {init: jsonInitFactory(elem)};
}
}
}
Expand Down
Loading

0 comments on commit 133d78c

Please sign in to comment.