Skip to content

Conversation

@gonfunko
Copy link
Contributor

@gonfunko gonfunko commented Aug 4, 2021

The basics

  • I branched from goog_module
  • My pull request is against goog_module
  • My code follows the style guide
  • My code is presented in the form suggested in the module
    conversion guide
  • I have run npm test.

The details

Resolves

Part of #5026

Proposed Changes

Converts core/events/events.js to goog.module with ES6 const/let.

Additional Information

This uses goog.forwardDeclare/goog.module.get to work around circular requires with Blockly.Workspace.

@google-cla google-cla bot added the cla: yes Used by Google's CLA checker. label Aug 4, 2021
@github-actions github-actions bot added this to the 2021_q3_release milestone Aug 4, 2021
@github-actions github-actions bot added type: cleanup and removed cla: yes Used by Google's CLA checker. labels Aug 4, 2021
@google-cla google-cla bot added the cla: yes Used by Google's CLA checker. label Aug 4, 2021
@google-cla
Copy link

google-cla bot commented Aug 4, 2021

☹️ Sorry, but only Googlers may change the label cla: yes.

@gonfunko gonfunko marked this pull request as ready for review August 12, 2021 17:41
@gonfunko gonfunko requested a review from a team as a code owner August 12, 2021 17:41
@gonfunko gonfunko requested a review from NeilFraser August 12, 2021 17:41
Blockly.Events.COMMENT_MOVE
];
const BUMP_EVENTS = [BLOCK_CREATE, BLOCK_MOVE, COMMENT_CREATE, COMMENT_MOVE];
exports.BUMP_EVENTS = BUMP_EVENTS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be evil to just say:

exports.BUMP_EVENTS = [exports.BLOCK_CREATE, exports.BLOCK_MOVE, exports.COMMENT_CREATE, exports.COMMENT_MOVE]

Then 27 different const statements could disappear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I quite understand the suggestion here, could you clarify?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @NeilFraser is suggesting that it is probably worth deviating from our usual convention of declare-then-export for all of these trivial declarations—I made a very similar suggestion about the flags exported by useragent.js in #5396.

Though in this case I smell a missing enum…

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Added to triage list in #5073.)

Blockly.Events.filter = function(queueIn, forward) {
var queue = queueIn.slice(); // Shallow copy of queue.
const filter = function(queueIn, forward) {
let queue = queueIn.slice(); // Shallow copy of queue.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think queue is const. The reverse is an in place operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets reassigned on line 409.

Blockly.Events.disabled_ = 0;
let disabled = 0;
/** @private */
exports.disabled_ = disabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line appears to be clobbered by the setter below. Delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closure isn't able to see properties that get added by Object.defineProperties, so this is here solely to inform the compiler that a .disabled_ property exists.


Object.defineProperties(exports, {
disabled_: {
set: function(newValue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who calls this setter? Seems odd to export a private property. I don't see anyone using this in our codebase in develop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used by test_helpers.js and workspace_test.js unfortunately.

*/
Blockly.Events.BumpEvent;
let BumpEvent;
exports.BumpEvent = BumpEvent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a typedef, does this need to be a let variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler complains if it's made a const because it isn't being assigned a value.

@gonfunko gonfunko merged commit a3b52aa into RaspberryPiFoundation:goog_module Aug 26, 2021
@gonfunko gonfunko deleted the events branch August 26, 2021 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Used by Google's CLA checker. type: cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants