Class: VariableMap
Defined in: packages/blockly/core/variable_map.ts:30
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.
Implements
Properties index
| Property | Description |
|---|---|
| workspace | The workspace this map belongs to. |
| potentialMap | True if this holds variables that don't exist in the workspace yet. |
Methods index
| Method | Description |
|---|---|
| clear | Clear the variable map. Fires events for every deletion. |
| renameVariable | Rename the given variable by updating its name in the variable map. |
| changeVariableType | - |
| createVariable | Create a variable with a given name, optional type, and optional ID. |
| addVariable | Adds the given variable to this variable map. |
| deleteVariable | Delete a variable and all of its uses without confirmation. |
| getVariable | Find the variable by the given name and type and return it. Return null if it is not found. |
| getVariableById | Find the variable by the given ID and return it. Return null if not found. |
| getVariablesOfType | Get a list containing all of the variables of a specified type. If type is null, return list of variables with empty string type. |
| getTypes | Returns a list of unique types of variables in this variable map. |
| getAllVariables | Return all variables of all types. |
Constructors
Constructor
new VariableMap(workspace, potentialMap?): VariableMap;
Defined in: packages/blockly/core/variable_map.ts:48
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
workspace | Workspace | undefined | The workspace this map belongs to. |
potentialMap | boolean | false | True if this holds variables that don't exist in the workspace yet. |
Returns
VariableMap
Properties
workspace
workspace: Workspace;
Defined in: packages/blockly/core/variable_map.ts:49
The workspace this map belongs to.
potentialMap
potentialMap: boolean = false;
Defined in: packages/blockly/core/variable_map.ts:50
True if this holds variables that don't exist in the workspace yet.
Methods
clear()
clear(): void;
Defined in: packages/blockly/core/variable_map.ts:54
Clear the variable map. Fires events for every deletion.
Returns
void
Implementation of
renameVariable()
renameVariable(variable, newName): IVariableModel<IVariableState>;
Defined in: packages/blockly/core/variable_map.ts:73
Rename the given variable by updating its name in the variable map.
Parameters
| Parameter | Type | Description |
|---|---|---|
variable | IVariableModel<IVariableState> | Variable to rename. |
newName | string | New variable name. |
Returns
IVariableModel<IVariableState>
The newly renamed variable.
Implementation of
changeVariableType()
changeVariableType(variable, newType): IVariableModel<IVariableState>;
Defined in: packages/blockly/core/variable_map.ts:102
Parameters
| Parameter | Type |
|---|---|
variable | IVariableModel<IVariableState> |
newType | string |
Returns
IVariableModel<IVariableState>
Implementation of
IVariableMap.changeVariableType
createVariable()
createVariable(
name,
opt_type?,
opt_id?
): IVariableModel<IVariableState>;
Defined in: packages/blockly/core/variable_map.ts:206
Create a variable with a given name, optional type, and optional ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the variable. This must be unique across variables and procedures. |
opt_type? | 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. |
opt_id? | string | The unique ID of the variable. This will default to a UUID. |
Returns
IVariableModel<IVariableState>
The newly created variable.
Implementation of
addVariable()
addVariable(variable): void;
Defined in: packages/blockly/core/variable_map.ts:261
Adds the given variable to this variable map.
Parameters
| Parameter | Type | Description |
|---|---|---|
variable | IVariableModel<IVariableState> | The variable to add. |
Returns
void
Implementation of
deleteVariable()
deleteVariable(variable): void;
Defined in: packages/blockly/core/variable_map.ts:278
Delete a variable and all of its uses without confirmation.
Parameters
| Parameter | Type | Description |
|---|---|---|
variable | IVariableModel<IVariableState> | Variable to delete. |
Returns
void
Implementation of
getVariable()
getVariable(name, opt_type?):
| IVariableModel<IVariableState>
| null;
Defined in: packages/blockly/core/variable_map.ts:319
Find the variable by the given name and type and return it. Return null if it is not found.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name to check for. |
opt_type? | string | The type of the variable. If not provided it defaults to the empty string, which is a specific type. |
Returns
| IVariableModel<IVariableState>
| null
The variable with the given name, or null if it was not found.
Implementation of
getVariableById()
getVariableById(id):
| IVariableModel<IVariableState>
| null;
Defined in: packages/blockly/core/variable_map.ts:340
Find the variable by the given ID and return it. Return null if not found.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The ID to check for. |
Returns
| IVariableModel<IVariableState>
| null
The variable with the given ID.
Implementation of
getVariablesOfType()
getVariablesOfType(type): IVariableModel<IVariableState>[];
Defined in: packages/blockly/core/variable_map.ts:357
Get a list containing all of the variables of a specified type. If type is null, return list of variables with empty string type.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | string | null | Type of the variables to find. |
Returns
IVariableModel<IVariableState>[]
The sought after variables of the passed in type. An empty array if none are found.
Implementation of
IVariableMap.getVariablesOfType
getTypes()
getTypes(): string[];
Defined in: packages/blockly/core/variable_map.ts:370
Returns a list of unique types of variables in this variable map.
Returns
string[]
A list of unique types of variables in this variable map.
Implementation of
getAllVariables()
getAllVariables(): IVariableModel<IVariableState>[];
Defined in: packages/blockly/core/variable_map.ts:379
Return all variables of all types.
Returns
IVariableModel<IVariableState>[]
List of variable models.