mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
chore: declare properties in the constructor instead of at first use (#5862)
This commit is contained in:
@@ -290,6 +290,19 @@ const Block = function(workspace, prototypeName, opt_id) {
|
||||
/** @type {?boolean} */
|
||||
this.rendered = null;
|
||||
|
||||
/**
|
||||
* String for block help, or function that returns a URL. Null for no help.
|
||||
* @type {string|Function}
|
||||
*/
|
||||
this.helpUrl = null;
|
||||
|
||||
/**
|
||||
* A bound callback function to use when the parent workspace changes.
|
||||
* @type {?function(Abstract)}
|
||||
* @private
|
||||
*/
|
||||
this.onchangeWrapper_ = null;
|
||||
|
||||
/**
|
||||
* A count of statement inputs on the block.
|
||||
* @type {number}
|
||||
|
||||
@@ -209,6 +209,12 @@ const BlockSvg = function(workspace, prototypeName, opt_id) {
|
||||
*/
|
||||
this.renderIsInProgress_ = false;
|
||||
|
||||
/**
|
||||
* Whether mousedown events have been bound yet.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.eventsInit_ = false;
|
||||
|
||||
/** @type {!WorkspaceSvg} */
|
||||
this.workspace = workspace;
|
||||
|
||||
@@ -98,6 +98,28 @@ const Comment = function(block) {
|
||||
*/
|
||||
this.onInputWrapper_ = null;
|
||||
|
||||
/**
|
||||
* The SVG element that contains the text edit area, or null if not created.
|
||||
* @type {?SVGForeignObjectElement}
|
||||
* @private
|
||||
*/
|
||||
this.foreignObject_ = null;
|
||||
|
||||
/**
|
||||
* The editable text area, or null if not created.
|
||||
* @type {?Element}
|
||||
* @private
|
||||
*/
|
||||
this.textarea_ = null;
|
||||
|
||||
/**
|
||||
* The top-level node of the comment text, or null if not created.
|
||||
* @type {?SVGTextElement}
|
||||
* @private
|
||||
*/
|
||||
this.paragraphElement_ = null;
|
||||
|
||||
|
||||
this.createIcon();
|
||||
};
|
||||
object.inherits(Comment, Icon);
|
||||
|
||||
53
core/icon.js
53
core/icon.js
@@ -47,33 +47,34 @@ const Icon = function(block) {
|
||||
* @type {?SVGGElement}
|
||||
*/
|
||||
this.iconGroup_ = null;
|
||||
|
||||
/**
|
||||
* Whether this icon gets hidden when the block is collapsed.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.collapseHidden = true;
|
||||
|
||||
/**
|
||||
* Height and width of icons.
|
||||
* @const
|
||||
*/
|
||||
this.SIZE = 17;
|
||||
|
||||
/**
|
||||
* Bubble UI (if visible).
|
||||
* @type {?Bubble}
|
||||
* @protected
|
||||
*/
|
||||
this.bubble_ = null;
|
||||
|
||||
/**
|
||||
* Absolute coordinate of icon's center.
|
||||
* @type {?Coordinate}
|
||||
* @protected
|
||||
*/
|
||||
this.iconXY_ = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Does this icon get hidden when the block is collapsed.
|
||||
*/
|
||||
Icon.prototype.collapseHidden = true;
|
||||
|
||||
/**
|
||||
* Height and width of icons.
|
||||
* @const
|
||||
*/
|
||||
Icon.prototype.SIZE = 17;
|
||||
|
||||
/**
|
||||
* Bubble UI (if visible).
|
||||
* @type {?Bubble}
|
||||
* @protected
|
||||
*/
|
||||
Icon.prototype.bubble_ = null;
|
||||
|
||||
/**
|
||||
* Absolute coordinate of icon's center.
|
||||
* @type {?Coordinate}
|
||||
* @protected
|
||||
*/
|
||||
Icon.prototype.iconXY_ = null;
|
||||
|
||||
/**
|
||||
* Create the icon on the block.
|
||||
*/
|
||||
@@ -197,7 +198,7 @@ Icon.prototype.getIconLocation = function() {
|
||||
*/
|
||||
// TODO (#2562): Remove getCorrectedSize.
|
||||
Icon.prototype.getCorrectedSize = function() {
|
||||
return new Size(Icon.prototype.SIZE, Icon.prototype.SIZE - 2);
|
||||
return new Size(this.SIZE, this.SIZE - 2);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,6 +78,30 @@ const Mutator = function(quarkNames) {
|
||||
* @private
|
||||
*/
|
||||
this.workspaceHeight_ = 0;
|
||||
|
||||
/**
|
||||
* The SVG element that is the parent of the mutator workspace, or null if
|
||||
* not created.
|
||||
* @type {?SVGSVGElement}
|
||||
* @private
|
||||
*/
|
||||
this.svgDialog_ = null;
|
||||
|
||||
/**
|
||||
* The root block of the mutator workspace, created by decomposing the source
|
||||
* block.
|
||||
* @type {?BlockSvg}
|
||||
* @private
|
||||
*/
|
||||
this.rootBlock_ = null;
|
||||
|
||||
/**
|
||||
* Function registered on the main workspace to update the mutator contents
|
||||
* when the main workspace changes.
|
||||
* @type {?Function}
|
||||
* @private
|
||||
*/
|
||||
this.sourceListener_ = null;
|
||||
};
|
||||
object.inherits(Mutator, Icon);
|
||||
|
||||
@@ -341,12 +365,12 @@ Mutator.prototype.setVisible = function(visible) {
|
||||
this.rootBlock_.moveBy(x, margin);
|
||||
// Save the initial connections, then listen for further changes.
|
||||
if (this.block_.saveConnections) {
|
||||
const thisMutator = this;
|
||||
const thisRootBlock = this.rootBlock_;
|
||||
const mutatorBlock =
|
||||
/** @type {{saveConnections: function(!Block)}} */ (this.block_);
|
||||
mutatorBlock.saveConnections(this.rootBlock_);
|
||||
this.sourceListener_ = function() {
|
||||
mutatorBlock.saveConnections(thisMutator.rootBlock_);
|
||||
mutatorBlock.saveConnections(thisRootBlock);
|
||||
};
|
||||
this.block_.workspace.addChangeListener(this.sourceListener_);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,13 @@ const Warning = function(block) {
|
||||
// The text_ object can contain multiple warnings.
|
||||
this.text_ = Object.create(null);
|
||||
|
||||
/**
|
||||
* The top-level node of the warning text, or null if not created.
|
||||
* @type {?SVGTextElement}
|
||||
* @private
|
||||
*/
|
||||
this.paragraphElement_ = null;
|
||||
|
||||
/**
|
||||
* Does this icon get hidden when the block is collapsed?
|
||||
* @type {boolean}
|
||||
|
||||
Reference in New Issue
Block a user