mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
@@ -188,17 +188,18 @@ Blockly.VariableMap.prototype.createVariable = function(name,
|
||||
if (opt_id && this.getVariableById(opt_id)) {
|
||||
throw Error('Variable id, "' + opt_id + '", is already in use.');
|
||||
}
|
||||
opt_id = opt_id || Blockly.utils.genUid();
|
||||
opt_type = opt_type || '';
|
||||
var id = opt_id || Blockly.utils.genUid();
|
||||
var type = opt_type || '';
|
||||
variable = new Blockly.VariableModel(this.workspace, name, type, id);
|
||||
|
||||
var variables = this.variableMap_[type] || [];
|
||||
variables.push(variable);
|
||||
// Delete the list of variables of this type, and re-add it so that
|
||||
// the most recent addition is at the end.
|
||||
// This is used so the toolbox's set block is set to the most recent variable.
|
||||
delete this.variableMap_[type];
|
||||
this.variableMap_[type] = variables;
|
||||
|
||||
variable = new Blockly.VariableModel(this.workspace, name, opt_type, opt_id);
|
||||
// If opt_type is not a key, create a new list.
|
||||
if (!this.variableMap_[opt_type]) {
|
||||
this.variableMap_[opt_type] = [variable];
|
||||
} else {
|
||||
// Else append the variable to the preexisting list.
|
||||
this.variableMap_[opt_type].push(variable);
|
||||
}
|
||||
return variable;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user