Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate core/utils/dom.js to goog.module syntax #5075

Merged
merged 6 commits into from
Jul 29, 2021

Conversation

gonfunko
Copy link
Contributor

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 locally already.

The details

Resolves

Part of #5026

@gonfunko gonfunko requested a review from a team as a code owner July 15, 2021 17:58
@gonfunko gonfunko requested a review from NeilFraser July 15, 2021 17:58
@cpcallen cpcallen added this to the 2021_q3_release milestone Jul 16, 2021
Copy link
Contributor

@NeilFraser NeilFraser left a comment

Choose a reason for hiding this comment

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

Just a few issues to fix first. Then LGTM.

Blockly.utils.dom.addClass = function(element, className) {
var classes = element.getAttribute('class') || '';
const addClass = function(element, className) {
let classes = element.getAttribute('class') || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, on line 117 it gets mutated.

const createSvgElement = function(name, attrs, opt_parent) {
const e = /** @type {T} */
(document.createElementNS(SVG_NS, String(name)));
for (const key in attrs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this let since it is redefined every loop iteration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because it is redefined every iteration; it's not the same variable taking on a new value, it's a new variable entirely each time through the loop.

const classList = classNames.split(' ');
for (let i = 0; i < classList.length; i++) {
const cssName = classList[i];
removeClass(element, cssName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just inline cssName, no need for a 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.

Done!

@gonfunko gonfunko merged commit c9a0333 into google:goog_module Jul 29, 2021
@gonfunko gonfunko deleted the dom branch July 29, 2021 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants