Move getOrCreateVariable to variables.js

This commit is contained in:
Rachel Fenichel
2017-12-05 13:08:01 -08:00
parent 39e689b458
commit e4844cd120
6 changed files with 168 additions and 86 deletions

View File

@@ -85,6 +85,16 @@ Blockly.Workspace = function(opt_options) {
*/
this.variableMap_ = new Blockly.VariableMap(this);
/**
* Blocks in the flyout can refer to variables that don't exist in the
* workspace. For instance, the "get item in list" block refers to an "item"
* variable regardless of whether the variable has been created yet.
* A FieldVariable must always refer to a Blockly.VariableModel. We reconcile
* these by tracking "potential" variables in the flyout. These variables
* become real when references to them are dragged into the main workspace.
* @type {!Blockly.VariableMap}
* @private
*/
this.potentialVariableMap_ = new Blockly.VariableMap(this);
};
@@ -199,6 +209,7 @@ Blockly.Workspace.prototype.clear = function() {
Blockly.Events.setGroup(false);
}
this.variableMap_.clear();
this.potentialVariableMap_.clear();
};
/**
@@ -628,6 +639,18 @@ Blockly.Workspace.prototype.getAllVariables = function() {
return this.variableMap_.getAllVariables();
};
/**
* Return the variable map that contains "potential" variables. These exist in
* the flyout but not in the workspace.
* TODO: Decide if this can be stored on the flyout workspace instead of the
* main workspace.
* @return {?Blockly.VariableMap} The potential variable map.
* @package
*/
Blockly.Workspace.prototype.getPotentialVariableMap = function() {
return this.potentialVariableMap_;
};
/**
* Database of all workspaces.
* @private