mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
Make the potential variable map null when not needed
This commit is contained in:
@@ -159,8 +159,8 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
if (childNode.nodeName.toLowerCase() == 'arg') {
|
||||
var varName = childNode.getAttribute('name');
|
||||
this.arguments_.push(varName);
|
||||
var variable = Blockly.Variables.getOrCreateVariable(this.workspace,
|
||||
null, varName, '');
|
||||
var variable = Blockly.Variables.getOrCreateVariablePackage(
|
||||
this.workspace, null, varName, '');
|
||||
this.argumentVarModels_.push(variable);
|
||||
}
|
||||
}
|
||||
@@ -217,8 +217,8 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
while (paramBlock) {
|
||||
var varName = paramBlock.getFieldValue('NAME');
|
||||
this.arguments_.push(varName);
|
||||
var variable = Blockly.Variables.getOrCreateVariable(this.workspace, null,
|
||||
varName, '');
|
||||
var variable = Blockly.Variables.getOrCreateVariablePackage(
|
||||
this.workspace, null, varName, '');
|
||||
this.argumentVarModels_.push(variable);
|
||||
this.paramIds_.push(paramBlock.id);
|
||||
paramBlock = paramBlock.nextConnection &&
|
||||
@@ -636,8 +636,8 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
// And rebuild the argument model list.
|
||||
this.argumentVarModels_ = [];
|
||||
for (var i = 0; i < this.arguments_.length; i++) {
|
||||
var variable = Blockly.Variables.getOrCreateVariable(this.workspace, null,
|
||||
this.arguments_[i], '');
|
||||
var variable = Blockly.Variables.getOrCreateVariablePackage(
|
||||
this.workspace, null, this.arguments_[i], '');
|
||||
this.argumentVarModels_.push(variable);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ Blockly.FieldVariable.prototype.initModel = function() {
|
||||
return; // Initialization already happened.
|
||||
}
|
||||
this.workspace_ = this.sourceBlock_.workspace;
|
||||
var variable = Blockly.Variables.getOrCreateVariable(
|
||||
var variable = Blockly.Variables.getOrCreateVariablePackage(
|
||||
this.workspace_, null, this.defaultVariableName, this.defaultType_);
|
||||
|
||||
// Don't fire a change event for this setValue. It would have null as the
|
||||
|
||||
@@ -250,6 +250,8 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) {
|
||||
|
||||
// Get variables from the main workspace rather than the target workspace.
|
||||
this.workspace_.variableMap_ = this.targetWorkspace_.getVariableMap();
|
||||
|
||||
this.workspace_.createPotentialVariableMap();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -385,7 +385,7 @@ Blockly.Variables.generateVariableFieldXml_ = function(variableModel) {
|
||||
* or name + type combination.
|
||||
* @package
|
||||
*/
|
||||
Blockly.Variables.getOrCreateVariable = function(workspace, id, opt_name,
|
||||
Blockly.Variables.getOrCreateVariablePackage = function(workspace, id, opt_name,
|
||||
opt_type) {
|
||||
var variable = Blockly.Variables.getVariable(workspace, id, opt_name,
|
||||
opt_type);
|
||||
@@ -420,14 +420,15 @@ Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) {
|
||||
if (!variable && potentialVariableMap) {
|
||||
variable = potentialVariableMap.getVariableById(id);
|
||||
}
|
||||
} else if (opt_name && (opt_type != undefined)){
|
||||
} else if (opt_name) {
|
||||
if (opt_type == undefined) {
|
||||
throw new 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);
|
||||
if (!variable && potentialVariableMap) {
|
||||
variable = potentialVariableMap.getVariable(opt_name, opt_type);
|
||||
}
|
||||
} else {
|
||||
throw new Error('Tried to look up a variable by name without a type');
|
||||
}
|
||||
return variable;
|
||||
};
|
||||
|
||||
@@ -95,7 +95,7 @@ Blockly.Workspace = function(opt_options) {
|
||||
* @type {!Blockly.VariableMap}
|
||||
* @private
|
||||
*/
|
||||
this.potentialVariableMap_ = new Blockly.VariableMap(this);
|
||||
this.potentialVariableMap_ = null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -197,7 +197,9 @@ Blockly.Workspace.prototype.clear = function() {
|
||||
Blockly.Events.setGroup(false);
|
||||
}
|
||||
this.variableMap_.clear();
|
||||
this.potentialVariableMap_.clear();
|
||||
if (this.potentialVariableMap_) {
|
||||
this.potentialVariableMap_.clear();
|
||||
}
|
||||
};
|
||||
|
||||
/* Begin functions that are just pass-throughs to the variable map. */
|
||||
@@ -469,7 +471,15 @@ Blockly.Workspace.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled
|
||||
* @package
|
||||
*/
|
||||
Blockly.Workspace.prototype.getPotentialVariableMap = function() {
|
||||
return this.isFlyout ? this.potentialVariableMap_ : null;
|
||||
return this.potentialVariableMap_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create and store the potential variable map for this workspace.
|
||||
* @package
|
||||
*/
|
||||
Blockly.Workspace.prototype.createPotentialVariableMap = function() {
|
||||
this.potentialVariableMap_ = new Blockly.VariableMap(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -758,8 +758,8 @@ Blockly.Xml.domToFieldVariable_ = function(workspace, xml, text, field) {
|
||||
type = '';
|
||||
}
|
||||
|
||||
var variable =
|
||||
Blockly.Variables.getOrCreateVariable(workspace, xml.id, text, type);
|
||||
var variable = Blockly.Variables.getOrCreateVariablePackage(workspace, xml.id,
|
||||
text, type);
|
||||
|
||||
// This should never happen :)
|
||||
if (type != null && type !== variable.type) {
|
||||
|
||||
Reference in New Issue
Block a user