Class: VariableModel
Defined in: packages/blockly/core/variable_model.ts:27
Class for a variable model. Holds information for the variable including name, ID, and type.
See
Implements
Methods index
| Method | Description |
|---|---|
| getId | Returns the ID for the variable. |
| getName | Returns the name of this variable. |
| setName | Updates the user-visible name of this variable. |
| getType | Returns the type of this variable. |
| setType | Updates the type of this variable. |
| getWorkspace | Returns the workspace this VariableModel belongs to. |
| save | Serializes this VariableModel. |
| load | Loads the persisted state into a new variable in the given workspace. |
Constructors
Constructor
new VariableModel(
workspace,
name,
opt_type?,
opt_id?
): VariableModel;
Defined in: packages/blockly/core/variable_model.ts:40
Parameters
| Parameter | Type | Description |
|---|---|---|
workspace | Workspace | The variable's workspace. |
name | string | The name of the variable. This is the user-visible name (e.g. 'my var' or '私の変数'), not the generated name. |
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
VariableModel
Methods
getId()
getId(): string;
Defined in: packages/blockly/core/variable_model.ts:64
Returns
string
The ID for the variable.
Implementation of
getName()
getName(): string;
Defined in: packages/blockly/core/variable_model.ts:69
Returns
string
The name of this variable.
Implementation of
setName()
setName(newName): this;
Defined in: packages/blockly/core/variable_model.ts:78
Updates the user-visible name of this variable.
Parameters
| Parameter | Type |
|---|---|
newName | string |
Returns
this
The newly-updated variable.
Implementation of
getType()
getType(): string;
Defined in: packages/blockly/core/variable_model.ts:84
Returns
string
The type of this variable.
Implementation of
setType()
setType(newType): this;
Defined in: packages/blockly/core/variable_model.ts:93
Updates the type of this variable.
Parameters
| Parameter | Type |
|---|---|
newType | string |
Returns
this
The newly-updated variable.
Implementation of
getWorkspace()
getWorkspace(): Workspace;
Defined in: packages/blockly/core/variable_model.ts:103
Returns the workspace this VariableModel belongs to.
Returns
The workspace this VariableModel belongs to.
Implementation of
save()
save(): IVariableState;
Defined in: packages/blockly/core/variable_model.ts:112
Serializes this VariableModel.
Returns
a JSON representation of this VariableModel.
Implementation of
load()
static load(state, workspace): void;
Defined in: packages/blockly/core/variable_model.ts:131
Loads the persisted state into a new variable in the given workspace.
Parameters
| Parameter | Type | Description |
|---|---|---|
state | IVariableState | The serialized state of a variable model from save(). |
workspace | Workspace | The workspace to create the new variable in. |
Returns
void