refactor: move properties into constructors and convert to classes (#5822)

* refactor: move properties to constructor in block_drag_surface.js

* refactor: move properties to constructor in block_svg.js

* refactor: move properties to constructor in block.js

* refactor: move properties to constructor in bubble.js

* refactor: move properties to constructor in connection.js

* refactor: move properties to constructor in flyout_base.js

* refactor: move properties to constructor in flyout_button.js

* refactor: move properties to constructor in generator.js

* refactor: move properties to constructor in grid.js

* refactor: move properties to constructor in input.js

* refactor: move properties to constructor in mutator.js

* refactor: move properties to constructor in scrollbar.js

* refactor: move properties to constructor in trashcan.js

* refactor: move properties to constructor in warning.js

* refactor: move properties to constructor in workspace_audio.js

* refactor: move properties to constructor in workspace_drag_surface_svg.js

* refactor: move properties to constructor in workspace_svg.js

* refactor: move properties to constructor in workspace.js

* refactor: move properties to constructor in zoom_controls.js

* chore: rebuild

* refactor: convert zoom_controls.js to es6 class and format

* refactor: convert workspace_audio.js to es6 class and format

* refactor: convert workspace_dragger.js to es6 class and format

* refactor: convert workspace_drag_surface_svg.js to es6 class and format

* refactor: convert variable_model.js to es6 class and format

* refactor: convert variable_map.js to es6 class and format

* refactor: convert theme.js to es6 class and format

* chore: remove bad comment
This commit is contained in:
Rachel Fenichel
2022-01-06 13:13:40 -08:00
committed by GitHub
parent 69642f74ea
commit df2eafb8dd
24 changed files with 2242 additions and 2252 deletions

View File

@@ -26,70 +26,71 @@ goog.require('Blockly.Events.VarCreate');
/**
* Class for a variable model.
* Holds information for the variable including name, ID, and type.
* @param {!Workspace} workspace The variable's workspace.
* @param {string} name The name of the variable. This is the user-visible name
* (e.g. 'my var' or '私の変数'), not the generated name.
* @param {string=} opt_type 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.
* @param {string=} opt_id The unique ID of the variable. This will default to
* a UUID.
* @see {Blockly.FieldVariable}
* @constructor
* @alias Blockly.VariableModel
*/
const VariableModel = function(workspace, name, opt_type, opt_id) {
class VariableModel {
/**
* The workspace the variable is in.
* @type {!Workspace}
* @param {!Workspace} workspace The variable's workspace.
* @param {string} name The name of the variable. This is the user-visible
* name (e.g. 'my var' or '私の変数'), not the generated name.
* @param {string=} opt_type 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.
* @param {string=} opt_id The unique ID of the variable. This will default to
* a UUID.
*/
this.workspace = workspace;
constructor(workspace, name, opt_type, opt_id) {
/**
* The workspace the variable is in.
* @type {!Workspace}
*/
this.workspace = workspace;
/**
* The name of the variable, typically defined by the user. It may be
* changed by the user.
* @type {string}
*/
this.name = name;
/**
* The type of the variable, such as 'int' or 'sound_effect'. This may be
* used to build a list of variables of a specific type. By default this is
* the empty string '', which is a specific type.
* @see {Blockly.FieldVariable}
* @type {string}
*/
this.type = opt_type || '';
/**
* A unique ID for the variable. This should be defined at creation and
* not change, even if the name changes. In most cases this should be a
* UUID.
* @type {string}
* @private
*/
this.id_ = opt_id || idGenerator.genUid();
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))(this));
}
/**
* The name of the variable, typically defined by the user. It may be
* changed by the user.
* @type {string}
* @return {string} The ID for the variable.
*/
this.name = name;
getId() {
return this.id_;
}
/**
* The type of the variable, such as 'int' or 'sound_effect'. This may be
* used to build a list of variables of a specific type. By default this is
* the empty string '', which is a specific type.
* @see {Blockly.FieldVariable}
* @type {string}
* A custom compare function for the VariableModel objects.
* @param {VariableModel} var1 First variable to compare.
* @param {VariableModel} var2 Second variable to compare.
* @return {number} -1 if name of var1 is less than name of var2, 0 if equal,
* and 1 if greater.
* @package
*/
this.type = opt_type || '';
/**
* A unique ID for the variable. This should be defined at creation and
* not change, even if the name changes. In most cases this should be a
* UUID.
* @type {string}
* @private
*/
this.id_ = opt_id || idGenerator.genUid();
eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))(this));
};
/**
* @return {string} The ID for the variable.
*/
VariableModel.prototype.getId = function() {
return this.id_;
};
/**
* A custom compare function for the VariableModel objects.
* @param {VariableModel} var1 First variable to compare.
* @param {VariableModel} var2 Second variable to compare.
* @return {number} -1 if name of var1 is less than name of var2, 0 if equal,
* and 1 if greater.
* @package
*/
VariableModel.compareByName = function(var1, var2) {
return var1.name.localeCompare(var2.name, undefined, {sensitivity: 'base'});
};
static compareByName(var1, var2) {
return var1.name.localeCompare(var2.name, undefined, {sensitivity: 'base'});
}
}
exports.VariableModel = VariableModel;