-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
There was a problem hiding this 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') || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this const
?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
core/utils/dom.js
Outdated
const classList = classNames.split(' '); | ||
for (let i = 0; i < classList.length; i++) { | ||
const cssName = classList[i]; | ||
removeClass(element, cssName); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
The basics
goog_module
goog_module
conversion guide
npm test
locally already.The details
Resolves
Part of #5026