Blockly. VariableMap
Constructor
VariableMap
new VariableMap(workspace)
Class for a variable map. This contains a dictionary data structure with variable types as keys and lists of variables as values. The list of variables are the type indicated by the key.
Parameter |
|
---|---|
workspace |
The workspace this map belongs to. Value must not be null. |
Property
workspace
non-null Blockly.Workspace
The workspace this map belongs to.
Methods
clear
clear()
Clear the variable map.
createVariable
createVariable(name, opt_type, opt_id) returns Blockly.VariableModel
Create a variable with a given name, optional type, and optional ID.
Parameter |
|
---|---|
name |
string The name of the variable. This must be unique across variables and procedures. |
opt_type |
Optional string The type of the variable like 'int' or 'string'. Does not need to be unique. Field_variable can filter variables based on their type. This will default to '' which is a specific type. Value may be null. |
opt_id |
Optional string The unique ID of the variable. This will default to a UUID. Value may be null. |
- Returns
-
non-null Blockly.VariableModel
The newly created variable.
deleteVariable
deleteVariable(variable)
Delete a variable.
Parameter |
|
---|---|
variable |
Variable to delete. Value must not be null. |
deleteVariableById
deleteVariableById(id)
Delete a variables by the passed in ID and all of its uses from this workspace. May prompt the user for confirmation.
Parameter |
|
---|---|
id |
string ID of variable to delete. |
deleteVariableInternal
deleteVariableInternal(variable, uses)
Deletes a variable and all of its uses from this workspace without asking the user for confirmation.
Parameter |
|
---|---|
variable |
Variable to delete. Value must not be null. |
uses |
Array of non-null Blockly.Block An array of uses of the variable. Value must not be null. |
getAllVariableNames
getAllVariableNames() returns Array of string
Returns all of the variable names of all types.
- Returns
-
non-null Array of string
All of the variable names of all types.
getAllVariables
getAllVariables() returns Array of non-null Blockly.VariableModel
Return all variables of all types.
- Returns
-
non-null Array of non-null Blockly.VariableModel
List of variable models.
getVariable
getVariable(name, opt_type) returns Blockly.VariableModel
Find the variable by the given name and type and return it. Return null if it is not found.
Parameter |
|
---|---|
name |
string The name to check for. |
opt_type |
Optional string The type of the variable. If not provided it defaults to the empty string, which is a specific type. Value may be null. |
- Returns
-
Blockly.VariableModel
The variable with the given name, or null if it was not found.
getVariableById
getVariableById(id) returns Blockly.VariableModel
Find the variable by the given ID and return it. Return null if it is not found.
Parameter |
|
---|---|
id |
string The ID to check for. |
- Returns
-
Blockly.VariableModel
The variable with the given ID.
getVariablesOfType
getVariablesOfType(type) returns Array of non-null Blockly.VariableModel
Get a list containing all of the variables of a specified type. If type is null, return list of variables with empty string type.
Parameter |
|
---|---|
type |
string Type of the variables to find. Value may be null. |
- Returns
-
non-null Array of non-null Blockly.VariableModel
The sought after variables of the passed in type. An empty array if none are found.
getVariableTypes
getVariableTypes(ws) returns Array of string
Return all variable and potential variable types. This list always contains the empty string.
Parameter |
|
---|---|
ws |
The workspace used to look for potential variables. This can be different than the workspace stored on this object if the passed in ws is a flyout workspace. Value may be null. |
- Returns
-
non-null Array of string
List of variable types.
getVariableUsesById
getVariableUsesById(id) returns Array of non-null Blockly.Block
Find all the uses of a named variable.
Parameter |
|
---|---|
id |
string ID of the variable to find. |
- Returns
-
non-null Array of non-null Blockly.Block
Array of block usages.
renameVariable
renameVariable(variable, newName)
Rename the given variable by updating its name in the variable map.
Parameter |
|
---|---|
variable |
Variable to rename. Value must not be null. |
newName |
string New variable name. |
renameVariableById
renameVariableById(id, newName)
Rename a variable by updating its name in the variable map. Identify the variable to rename with the given ID.
Parameter |
|
---|---|
id |
string ID of the variable to rename. |
newName |
string New variable name. |