Skip to content

Commit

Permalink
refactor: convert some files to es classes (google#5917)
Browse files Browse the repository at this point in the history
* refactor: update several files to es6 classes

* refactor: update several files to es6 classes

* chore: add some type casts for specificity about event types

* chore: run formatter

* chore: rebuild
  • Loading branch information
rachel-fenichel authored Feb 9, 2022
1 parent e3f40a6 commit 9e8c5ea
Show file tree
Hide file tree
Showing 22 changed files with 2,441 additions and 2,387 deletions.
5 changes: 4 additions & 1 deletion core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const parsing = goog.require('Blockly.utils.parsing');
const {Abstract} = goog.requireType('Blockly.Events.Abstract');
const {Align, Input} = goog.require('Blockly.Input');
const {ASTNode} = goog.require('Blockly.ASTNode');
/* eslint-disable-next-line no-unused-vars */
const {BlockMove} = goog.requireType('Blockly.Events.BlockMove');
const {Blocks} = goog.require('Blockly.blocks');
/* eslint-disable-next-line no-unused-vars */
const {Comment} = goog.requireType('Blockly.Comment');
Expand Down Expand Up @@ -2098,7 +2100,8 @@ Block.prototype.moveBy = function(dx, dy) {
if (this.parentBlock_) {
throw Error('Block has parent.');
}
const event = new (eventUtils.get(eventUtils.BLOCK_MOVE))(this);
const event = /** @type {!BlockMove} */ (
new (eventUtils.get(eventUtils.BLOCK_MOVE))(this));
this.xy_.translate(dx, dy);
event.recordNew();
eventUtils.fire(event);
Expand Down
6 changes: 4 additions & 2 deletions core/block_dragger.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const dom = goog.require('Blockly.utils.dom');
const eventUtils = goog.require('Blockly.Events.utils');
const registry = goog.require('Blockly.registry');
/* eslint-disable-next-line no-unused-vars */
const {BlockMove} = goog.requireType('Blockly.Events.BlockMove');
/* eslint-disable-next-line no-unused-vars */
const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
const {Coordinate} = goog.require('Blockly.utils.Coordinate');
/* eslint-disable-next-line no-unused-vars */
Expand Down Expand Up @@ -376,8 +378,8 @@ const BlockDragger = class {
* @protected
*/
fireMoveEvent_() {
const event =
new (eventUtils.get(eventUtils.BLOCK_MOVE))(this.draggingBlock_);
const event = /** @type {!BlockMove} */
(new (eventUtils.get(eventUtils.BLOCK_MOVE))(this.draggingBlock_));
event.oldCoordinate = this.startXY_;
event.recordNew();
eventUtils.fire(event);
Expand Down
5 changes: 4 additions & 1 deletion core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const userAgent = goog.require('Blockly.utils.userAgent');
const {ASTNode} = goog.require('Blockly.ASTNode');
const {Block} = goog.require('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
const {BlockMove} = goog.requireType('Blockly.Events.BlockMove');
/* eslint-disable-next-line no-unused-vars */
const {Comment} = goog.requireType('Blockly.Comment');
const {ConnectionType} = goog.require('Blockly.ConnectionType');
/* eslint-disable-next-line no-unused-vars */
Expand Down Expand Up @@ -468,7 +470,8 @@ BlockSvg.prototype.moveBy = function(dx, dy) {
const eventsEnabled = eventUtils.isEnabled();
let event;
if (eventsEnabled) {
event = new (eventUtils.get(eventUtils.BLOCK_MOVE))(this);
event = /** @type {!BlockMove} */
(new (eventUtils.get(eventUtils.BLOCK_MOVE))(this));
}
const xy = this.getRelativeToSurfaceXY();
this.translate(xy.x + dx, xy.y + dy);
Expand Down
7 changes: 5 additions & 2 deletions core/bubble_dragger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const eventUtils = goog.require('Blockly.Events.utils');
const svgMath = goog.require('Blockly.utils.svgMath');
/* eslint-disable-next-line no-unused-vars */
const {BlockDragSurfaceSvg} = goog.requireType('Blockly.BlockDragSurfaceSvg');
/* eslint-disable-next-line no-unused-vars */
const {CommentMove} = goog.requireType('Blockly.Events.CommentMove');
const {ComponentManager} = goog.require('Blockly.ComponentManager');
const {Coordinate} = goog.require('Blockly.utils.Coordinate');
/* eslint-disable-next-line no-unused-vars */
Expand Down Expand Up @@ -244,8 +246,9 @@ const BubbleDragger = class {
if (this.draggingBubble_.isComment) {
// TODO (adodson): Resolve build errors when requiring
// WorkspaceCommentSvg.
const event = new (eventUtils.get(eventUtils.COMMENT_MOVE))(
/** @type {!WorkspaceCommentSvg} */ (this.draggingBubble_));
const event = /** @type {!CommentMove} */
(new (eventUtils.get(eventUtils.COMMENT_MOVE))(
/** @type {!WorkspaceCommentSvg} */ (this.draggingBubble_)));
event.setOldCoordinate(this.startXY_);
event.recordNew();
eventUtils.fire(event);
Expand Down
Loading

0 comments on commit 9e8c5ea

Please sign in to comment.