Skip to main content

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

MethodDescription
getIdReturns the ID for the variable.
getNameReturns the name of this variable.
setNameUpdates the user-visible name of this variable.
getTypeReturns the type of this variable.
setTypeUpdates the type of this variable.
getWorkspaceReturns the workspace this VariableModel belongs to.
saveSerializes this VariableModel.
loadLoads 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

ParameterTypeDescription
workspaceWorkspaceThe variable's workspace.
namestringThe name of the variable. This is the user-visible name (e.g. 'my var' or '私の変数'), not the generated name.
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

VariableModel

Methods

getId()

getId(): string;

Defined in: packages/blockly/core/variable_model.ts:64

Returns

string

The ID for the variable.

Implementation of

IVariableModel.getId


getName()

getName(): string;

Defined in: packages/blockly/core/variable_model.ts:69

Returns

string

The name of this variable.

Implementation of

IVariableModel.getName


setName()

setName(newName): this;

Defined in: packages/blockly/core/variable_model.ts:78

Updates the user-visible name of this variable.

Parameters

ParameterType
newNamestring

Returns

this

The newly-updated variable.

Implementation of

IVariableModel.setName


getType()

getType(): string;

Defined in: packages/blockly/core/variable_model.ts:84

Returns

string

The type of this variable.

Implementation of

IVariableModel.getType


setType()

setType(newType): this;

Defined in: packages/blockly/core/variable_model.ts:93

Updates the type of this variable.

Parameters

ParameterType
newTypestring

Returns

this

The newly-updated variable.

Implementation of

IVariableModel.setType


getWorkspace()

getWorkspace(): Workspace;

Defined in: packages/blockly/core/variable_model.ts:103

Returns the workspace this VariableModel belongs to.

Returns

Workspace

The workspace this VariableModel belongs to.

Implementation of

IVariableModel.getWorkspace


save()

save(): IVariableState;

Defined in: packages/blockly/core/variable_model.ts:112

Serializes this VariableModel.

Returns

IVariableState

a JSON representation of this VariableModel.

Implementation of

IVariableModel.save


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

ParameterTypeDescription
stateIVariableStateThe serialized state of a variable model from save().
workspaceWorkspaceThe workspace to create the new variable in.

Returns

void