Skip to content

Commit

Permalink
Rename to IProcedureBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed May 8, 2021
1 parent 918bdc2 commit c8a065f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
10 changes: 5 additions & 5 deletions core/interfaces/i_procedure_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

'use strict';

goog.provide('Blockly.Procedures.ProcedureBlock');
goog.provide('Blockly.IProcedureBlock');

/**
* A procedure block interface.
* @interface
*/
Blockly.Procedures.ProcedureBlock = function() {};
Blockly.IProcedureBlock = function() {};

/**
* Returns the name of the procedure the procedure block calls.
* @return {string}
*/
Blockly.Procedures.ProcedureBlock.prototype.getProcedureCall;
Blockly.IProcedureBlock.prototype.getProcedureCall;

/**
* Renames the procedure from the old name to the new name. If the procedure
Expand All @@ -31,7 +31,7 @@ Blockly.Procedures.ProcedureBlock.prototype.getProcedureCall;
* @param {string} oldName The old name of the procedure.
* @param {string} newName The new name of hte procedure.
*/
Blockly.Procedures.ProcedureBlock.prototype.renameProcedure;
Blockly.IProcedureBlock.prototype.renameProcedure;

/**
* Returns the signature of the procedure block's procedure definition.
Expand All @@ -40,4 +40,4 @@ Blockly.Procedures.ProcedureBlock.prototype.renameProcedure;
* - {!Array<string>} a list of all its arguments
* - {boolean} whether it has a return value or not
*/
Blockly.Procedures.ProcedureBlock.prototype.getProcedureDef;
Blockly.IProcedureBlock.prototype.getProcedureDef;
26 changes: 18 additions & 8 deletions core/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ goog.require('Blockly.Events.BlockChange');
goog.require('Blockly.Field');
goog.require('Blockly.Msg');
goog.require('Blockly.Names');
goog.require('Blockly.Procedures.ProcedureBlock');
goog.require('Blockly.utils.xml');
goog.require('Blockly.Workspace');
goog.require('Blockly.Xml');

goog.requireType('Blockly.Block');
goog.requireType('Blockly.Events.Abstract');
goog.requireType('Blockly.IProcedureBlock');
goog.requireType('Blockly.WorkspaceSvg');


Expand All @@ -48,6 +48,16 @@ Blockly.Procedures.NAME_TYPE = Blockly.PROCEDURE_CATEGORY_NAME;
*/
Blockly.Procedures.DEFAULT_ARG = 'x';

/**
* A procedure block interface. Will be deprecated for Blockly.IProcedureBlock.
* @typedef {{
* getProcedureCall: function():string,
* renameProcedure: function(string,string),
* getProcedureDef: function():!Array
* }}
*/
Blockly.Procedures.ProcedureBlock;

/**
* Find all user-created procedure definitions in a workspace.
* @param {!Blockly.Workspace} root Root workspace.
Expand All @@ -59,10 +69,10 @@ Blockly.Procedures.DEFAULT_ARG = 'x';
Blockly.Procedures.allProcedures = function(root) {
var proceduresNoReturn = root.getBlocksByType('procedures_defnoreturn', false)
.map(function(block) {
return /** @type {!Blockly.Procedures.ProcedureBlock} */ (block).getProcedureDef();
return /** @type {!Blockly.IProcedureBlock} */ (block).getProcedureDef();
});
var proceduresReturn = root.getBlocksByType('procedures_defreturn', false).map(function(block) {
return /** @type {!Blockly.Procedures.ProcedureBlock} */ (block).getProcedureDef();
return /** @type {!Blockly.IProcedureBlock} */ (block).getProcedureDef();
});
proceduresNoReturn.sort(Blockly.Procedures.procTupleComparator_);
proceduresReturn.sort(Blockly.Procedures.procTupleComparator_);
Expand Down Expand Up @@ -137,7 +147,7 @@ Blockly.Procedures.isNameUsed = function(name, workspace, opt_exclude) {
continue;
}
if (blocks[i].getProcedureDef) {
var procedureBlock = /** @type {!Blockly.Procedures.ProcedureBlock} */ (
var procedureBlock = /** @type {!Blockly.IProcedureBlock} */ (
blocks[i]);
var procName = procedureBlock.getProcedureDef();
if (Blockly.Names.equals(procName[0], name)) {
Expand Down Expand Up @@ -166,7 +176,7 @@ Blockly.Procedures.rename = function(name) {
var blocks = this.getSourceBlock().workspace.getAllBlocks(false);
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].renameProcedure) {
var procedureBlock = /** @type {!Blockly.Procedures.ProcedureBlock} */ (
var procedureBlock = /** @type {!Blockly.IProcedureBlock} */ (
blocks[i]);
procedureBlock.renameProcedure(
/** @type {string} */ (oldName), legalName);
Expand Down Expand Up @@ -336,7 +346,7 @@ Blockly.Procedures.getCallers = function(name, workspace) {
// Iterate through every block and check the name.
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].getProcedureCall) {
var procedureBlock = /** @type {!Blockly.Procedures.ProcedureBlock} */ (
var procedureBlock = /** @type {!Blockly.IProcedureBlock} */ (
blocks[i]);
var procName = procedureBlock.getProcedureCall();
// Procedure name may be null if the block is only half-built.
Expand All @@ -355,7 +365,7 @@ Blockly.Procedures.getCallers = function(name, workspace) {
*/
Blockly.Procedures.mutateCallers = function(defBlock) {
var oldRecordUndo = Blockly.Events.recordUndo;
var procedureBlock = /** @type {!Blockly.Procedures.ProcedureBlock} */ (
var procedureBlock = /** @type {!Blockly.IProcedureBlock} */ (
defBlock);
var name = procedureBlock.getProcedureDef()[0];
var xmlElement = defBlock.mutationToDom(true);
Expand Down Expand Up @@ -391,7 +401,7 @@ Blockly.Procedures.getDefinition = function(name, workspace) {
var blocks = workspace.getAllBlocks(false);
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].getProcedureDef) {
var procedureBlock = /** @type {!Blockly.Procedures.ProcedureBlock} */ (
var procedureBlock = /** @type {!Blockly.IProcedureBlock} */ (
blocks[i]);
var tuple = procedureBlock.getProcedureDef();
if (tuple && Blockly.Names.equals(tuple[0], name)) {
Expand Down

0 comments on commit c8a065f

Please sign in to comment.