Skip to content

Commit

Permalink
chore: declare properties in the constructor instead of at first use (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-fenichel authored Jan 7, 2022
1 parent 9d8eeb3 commit 6ee6389
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 25 deletions.
13 changes: 13 additions & 0 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 6 additions & 0 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions core/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 24 additions & 23 deletions core/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,33 @@ const Icon = function(block) {
* @type {?SVGGElement}
*/
this.iconGroup_ = null;
};

/**
* Does this icon get hidden when the block is collapsed.
*/
Icon.prototype.collapseHidden = true;
/**
* Whether this icon gets hidden when the block is collapsed.
* @type {boolean}
*/
this.collapseHidden = true;

/**
* Height and width of icons.
* @const
*/
Icon.prototype.SIZE = 17;
/**
* Height and width of icons.
* @const
*/
this.SIZE = 17;

/**
* Bubble UI (if visible).
* @type {?Bubble}
* @protected
*/
Icon.prototype.bubble_ = null;
/**
* Bubble UI (if visible).
* @type {?Bubble}
* @protected
*/
this.bubble_ = null;

/**
* Absolute coordinate of icon's center.
* @type {?Coordinate}
* @protected
*/
Icon.prototype.iconXY_ = null;
/**
* Absolute coordinate of icon's center.
* @type {?Coordinate}
* @protected
*/
this.iconXY_ = null;
};

/**
* Create the icon on the block.
Expand Down Expand Up @@ -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);
};

/**
Expand Down
28 changes: 26 additions & 2 deletions core/mutator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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_);
}
Expand Down
7 changes: 7 additions & 0 deletions core/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 6ee6389

Please sign in to comment.