mirror of
https://github.com/google/blockly.git
synced 2026-01-20 15:27:09 +01:00
Fix 11 warnings related to variables and variable_model. (#3278)
* Fix 10 warnings related to variables and variable_model.
This commit is contained in:
@@ -300,6 +300,14 @@ Blockly.Block.prototype.domToMutation;
|
||||
*/
|
||||
Blockly.Block.prototype.suppressPrefixSuffix;
|
||||
|
||||
/**
|
||||
* An optional property for declaring developer variables. Return a list of
|
||||
* variable names for use by generators. Developer variables are never shown to
|
||||
* the user, but are declared as global variables in the generated code.
|
||||
* @type {?function():!Array.<string>}
|
||||
*/
|
||||
Blockly.Block.prototype.getDeveloperVariables;
|
||||
|
||||
/**
|
||||
* Dispose of this block.
|
||||
* @param {boolean} healStack If true, then try to heal any gap by connecting
|
||||
|
||||
@@ -168,7 +168,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable,
|
||||
* their type. This will default to '' which is a specific type.
|
||||
* @param {?string=} opt_id The unique ID of the variable. This will default to
|
||||
* a UUID.
|
||||
* @return {Blockly.VariableModel} The newly created variable.
|
||||
* @return {!Blockly.VariableModel} The newly created variable.
|
||||
*/
|
||||
Blockly.VariableMap.prototype.createVariable = function(name,
|
||||
opt_type, opt_id) {
|
||||
@@ -248,13 +248,13 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) {
|
||||
replace('%2', variableName);
|
||||
Blockly.confirm(confirmText,
|
||||
function(ok) {
|
||||
if (ok) {
|
||||
map.deleteVariableInternal_(variable, uses);
|
||||
if (ok && variable) {
|
||||
map.deleteVariableInternal(variable, uses);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// No confirmation necessary for a single block.
|
||||
map.deleteVariableInternal_(variable, uses);
|
||||
map.deleteVariableInternal(variable, uses);
|
||||
}
|
||||
} else {
|
||||
console.warn("Can't delete non-existent variable: " + id);
|
||||
@@ -266,9 +266,9 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) {
|
||||
* user for confirmation.
|
||||
* @param {!Blockly.VariableModel} variable Variable to delete.
|
||||
* @param {!Array.<!Blockly.Block>} uses An array of uses of the variable.
|
||||
* @private
|
||||
* @package
|
||||
*/
|
||||
Blockly.VariableMap.prototype.deleteVariableInternal_ = function(variable,
|
||||
Blockly.VariableMap.prototype.deleteVariableInternal = function(variable,
|
||||
uses) {
|
||||
var existingGroup = Blockly.Events.getGroup();
|
||||
if (!existingGroup) {
|
||||
@@ -292,7 +292,7 @@ Blockly.VariableMap.prototype.deleteVariableInternal_ = function(variable,
|
||||
* Find the variable by the given name and type and return it. Return null if
|
||||
* it is not found.
|
||||
* @param {string} name The name to check for.
|
||||
* @param {string=} opt_type The type of the variable. If not provided it
|
||||
* @param {?string=} opt_type The type of the variable. If not provided it
|
||||
* defaults to the empty string, which is a specific type.
|
||||
* @return {Blockly.VariableModel} The variable with the given name, or null if
|
||||
* it was not found.
|
||||
|
||||
@@ -500,10 +500,11 @@ Blockly.Variables.getOrCreateVariablePackage = function(workspace, id, opt_name,
|
||||
*/
|
||||
Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) {
|
||||
var potentialVariableMap = workspace.getPotentialVariableMap();
|
||||
var variable = null;
|
||||
// Try to just get the variable, by ID if possible.
|
||||
if (id) {
|
||||
// Look in the real variable map before checking the potential variable map.
|
||||
var variable = workspace.getVariableById(id);
|
||||
variable = workspace.getVariableById(id);
|
||||
if (!variable && potentialVariableMap) {
|
||||
variable = potentialVariableMap.getVariableById(id);
|
||||
}
|
||||
@@ -518,7 +519,7 @@ Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) {
|
||||
throw Error('Tried to look up a variable by name without a type');
|
||||
}
|
||||
// Otherwise look up by name and type.
|
||||
var variable = workspace.getVariable(opt_name, opt_type);
|
||||
variable = workspace.getVariable(opt_name, opt_type);
|
||||
if (!variable && potentialVariableMap) {
|
||||
variable = potentialVariableMap.getVariable(opt_name, opt_type);
|
||||
}
|
||||
@@ -547,10 +548,11 @@ Blockly.Variables.createVariable_ = function(workspace, id, opt_name,
|
||||
}
|
||||
|
||||
// Create a potential variable if in the flyout.
|
||||
var variable = null;
|
||||
if (potentialVariableMap) {
|
||||
var variable = potentialVariableMap.createVariable(opt_name, opt_type, id);
|
||||
variable = potentialVariableMap.createVariable(opt_name, opt_type, id);
|
||||
} else { // In the main workspace, create a real variable.
|
||||
var variable = workspace.createVariable(opt_name, opt_type, id);
|
||||
variable = workspace.createVariable(opt_name, opt_type, id);
|
||||
}
|
||||
return variable;
|
||||
};
|
||||
|
||||
@@ -33,15 +33,15 @@ goog.require('Blockly.VariableModel');
|
||||
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) {
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(),
|
||||
null, 'String');
|
||||
undefined, 'String');
|
||||
};
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_Number = function(button) {
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(),
|
||||
null, 'Number');
|
||||
undefined, 'Number');
|
||||
};
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_Colour = function(button) {
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(),
|
||||
null, 'Colour');
|
||||
undefined, 'Colour');
|
||||
};
|
||||
/**
|
||||
* Construct the elements (blocks and button) required by the flyout for the
|
||||
|
||||
@@ -516,7 +516,7 @@ Blockly.Workspace.prototype.renameVariableById = function(id, newName) {
|
||||
* their type. This will default to '' which is a specific type.
|
||||
* @param {?string=} opt_id The unique ID of the variable. This will default to
|
||||
* a UUID.
|
||||
* @return {Blockly.VariableModel} The newly created variable.
|
||||
* @return {!Blockly.VariableModel} The newly created variable.
|
||||
*/
|
||||
Blockly.Workspace.prototype.createVariable = function(name, opt_type, opt_id) {
|
||||
return this.variableMap_.createVariable(name, opt_type, opt_id);
|
||||
@@ -548,7 +548,7 @@ Blockly.Workspace.prototype.deleteVariableById = function(id) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.Workspace.prototype.deleteVariableInternal_ = function(variable, uses) {
|
||||
this.variableMap_.deleteVariableInternal_(variable, uses);
|
||||
this.variableMap_.deleteVariableInternal(variable, uses);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -593,7 +593,7 @@ Blockly.Workspace.prototype.getVariableById = function(id) {
|
||||
* Find the variable with the specified type. If type is null, return list of
|
||||
* variables with empty string type.
|
||||
* @param {?string} type Type of the variables to find.
|
||||
* @return {Array.<Blockly.VariableModel>} The sought after variables of the
|
||||
* @return {!Array.<!Blockly.VariableModel>} The sought after variables of the
|
||||
* passed in type. An empty array if none are found.
|
||||
*/
|
||||
Blockly.Workspace.prototype.getVariablesOfType = function(type) {
|
||||
|
||||
Reference in New Issue
Block a user