Skip to main content

Class: VariableMap

Defined in: packages/blockly/core/variable_map.ts:33

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​

PropertyDescription
workspaceThe workspace this map belongs to.
potentialMapTrue if this holds variables that don't exist in the workspace yet.

Methods index​

MethodDescription
clearClear the variable map. Fires events for every deletion.
renameVariableRename the given variable by updating its name in the variable map.
changeVariableType-
createVariableCreate a variable with a given name, optional type, and optional ID.
addVariableAdds the given variable to this variable map.
deleteVariableDelete a variable and all of its uses without confirmation.
getVariableFind the variable by the given name and type and return it. Return null if it is not found.
getVariableByIdFind the variable by the given ID and return it. Return null if not found.
getVariablesOfTypeGet a list containing all of the variables of a specified type. If type is null, return list of variables with empty string type.
getTypesReturns a list of unique types of variables in this variable map.
getAllVariablesReturn all variables of all types.

Constructors​

Constructor​

new VariableMap(workspace, potentialMap?): VariableMap;

Defined in: packages/blockly/core/variable_map.ts:51

Parameters​

ParameterTypeDefault valueDescription
workspaceWorkspaceundefinedThe workspace this map belongs to.
potentialMapbooleanfalseTrue 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:52

The workspace this map belongs to.


potentialMap​

potentialMap: boolean = false;

Defined in: packages/blockly/core/variable_map.ts:53

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:57

Clear the variable map. Fires events for every deletion.

Returns​

void

Implementation of​

IVariableMap.clear


renameVariable()​

renameVariable(variable, newName): IVariableModel<IVariableState>;

Defined in: packages/blockly/core/variable_map.ts:76

Rename the given variable by updating its name in the variable map.

Parameters​

ParameterTypeDescription
variableIVariableModel<IVariableState>Variable to rename.
newNamestringNew variable name.

Returns​

IVariableModel<IVariableState>

The newly renamed variable.

Implementation of​

IVariableMap.renameVariable


changeVariableType()​

changeVariableType(variable, newType): IVariableModel<IVariableState>;

Defined in: packages/blockly/core/variable_map.ts:105

Parameters​

ParameterType
variableIVariableModel<IVariableState>
newTypestring

Returns​

IVariableModel<IVariableState>

Implementation of​

IVariableMap.changeVariableType


createVariable()​

createVariable(
name,
opt_type?,
opt_id?
): IVariableModel<IVariableState>;

Defined in: packages/blockly/core/variable_map.ts:209

Create a variable with a given name, optional type, and optional ID.

Parameters​

ParameterTypeDescription
namestringThe name of the variable. This must be unique across variables and procedures.
opt_type?stringThe 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?stringThe unique ID of the variable. This will default to a UUID.

Returns​

IVariableModel<IVariableState>

The newly created variable.

Implementation of​

IVariableMap.createVariable


addVariable()​

addVariable(variable): void;

Defined in: packages/blockly/core/variable_map.ts:264

Adds the given variable to this variable map.

Parameters​

ParameterTypeDescription
variableIVariableModel<IVariableState>The variable to add.

Returns​

void

Implementation of​

IVariableMap.addVariable


deleteVariable()​

deleteVariable(variable): void;

Defined in: packages/blockly/core/variable_map.ts:281

Delete a variable and all of its uses without confirmation.

Parameters​

ParameterTypeDescription
variableIVariableModel<IVariableState>Variable to delete.

Returns​

void

Implementation of​

IVariableMap.deleteVariable


getVariable()​

getVariable(name, opt_type?):
| IVariableModel<IVariableState>
| null;

Defined in: packages/blockly/core/variable_map.ts:322

Find the variable by the given name and type and return it. Return null if it is not found.

Parameters​

ParameterTypeDescription
namestringThe name to check for.
opt_type?stringThe 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​

IVariableMap.getVariable


getVariableById()​

getVariableById(id):
| IVariableModel<IVariableState>
| null;

Defined in: packages/blockly/core/variable_map.ts:343

Find the variable by the given ID and return it. Return null if not found.

Parameters​

ParameterTypeDescription
idstringThe ID to check for.

Returns​

| IVariableModel<IVariableState> | null

The variable with the given ID.

Implementation of​

IVariableMap.getVariableById


getVariablesOfType()​

getVariablesOfType(type): IVariableModel<IVariableState>[];

Defined in: packages/blockly/core/variable_map.ts:360

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​

ParameterTypeDescription
typestring | nullType 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:373

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​

IVariableMap.getTypes


getAllVariables()​

getAllVariables(): IVariableModel<IVariableState>[];

Defined in: packages/blockly/core/variable_map.ts:382

Return all variables of all types.

Returns​

IVariableModel<IVariableState>[]

List of variable models.

Implementation of​

IVariableMap.getAllVariables