-
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
chore: remove some underscores in icon-related classes #6583
chore: remove some underscores in icon-related classes #6583
Conversation
core/comment.ts
Outdated
const doubleBorderWidth = 2 * Bubble.BORDER_WIDTH; | ||
const widthMinusBorder = size.width - doubleBorderWidth; | ||
const heightMinusBorder = size.height - doubleBorderWidth; | ||
this.foreignObject_!.setAttribute('width', `${widthMinusBorder}`); | ||
this.foreignObject_!.setAttribute('height', `${heightMinusBorder}`); | ||
this.foreignObject!.setAttribute('width', `${widthMinusBorder}`); |
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.
in the interest of type safety I think it'd be reasonable to add a if (!this.foreignObject || !this.textarea_) return;
at the top and cut out the non-null assertions
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.
core/icon.ts
Outdated
@@ -175,7 +175,7 @@ export abstract class Icon { | |||
* | |||
* @param _group The icon group. | |||
*/ | |||
protected drawIcon_(_group: Element) {} | |||
protected drawIcon_(_group: SVGGElement) {} |
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.
do we allow developers to create their own icon classes and pass them to our code? I don't think so, but I'm not 100%
if so then this might be too restrictive if they would otherwise be able to pass e.g. a div with an image tag or something.
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.
Good point. I don't think that we do, but it is technically a breaking change so I'll put it back.
core/mutator.ts
Outdated
} | ||
} | ||
if (this.iconGroup_) { | ||
dom.removeClass(this.iconGroup_, 'blocklyIconGroupReadonly'); |
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.
seems like we are now always removing the class, but before we were adding it or removing it depending on the new editable state. I don't see where we're ever adding the class, is this change intended?
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.
And this is why we have code reviews! Nope, I misread and thought they were doing the same thing. Good catch.
core/mutator.ts
Outdated
private resizeBubble_() { | ||
private resizeBubble() { | ||
// If the bubble exists, the workspace also exists. | ||
const ws = this.workspace as WorkspaceSvg; |
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.
I like using the !
instead of casting, the intention is more clear (with the cast, i scrolled back up to see if this was allowed to be a plain Workspace
to understand why we needed the cast). does it work to const ws = this.workspace!;
?
Alternatively I think if (!this.workspace) return;
is even better since it's type safer and about the same amount of code. you could do the same below in setVisible
to eliminate more non-null assertions
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 and done.
core/mutator.ts
Outdated
this.rootBlock_ = block.decompose!(this.workspace_!)!; | ||
const blocks = this.rootBlock_!.getDescendants(false); | ||
this.rootBlock = block.decompose!(this.workspace!)!; | ||
const blocks = this.rootBlock!.getDescendants(false); |
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.
you can eliminate the !
here since you've already asserted above
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.
@@ -456,7 +454,7 @@ export class Mutator extends Icon { | |||
block.rendered = false; | |||
|
|||
// Allow the source block to rebuild itself. | |||
block.compose!(this.rootBlock_); | |||
block.compose!(this.rootBlock); |
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.
random aside: pretty sure we could have block
say it is a type that describes a "Block where we know the compose property is present" since we know it actually must be present if we are calling this, using union types. that would be fancy and i'm only mentioning it here because i'm excited by how specific we can get with TS, not because i think we should actually change anything rn
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.
Yes! I'm not doing it now but I agree that there should be a way to communicate that to the compiler and it would be fancy.
@@ -143,8 +143,8 @@ export class Warning extends Icon { | |||
*/ | |||
getText(): string { | |||
const allWarnings = []; | |||
for (const id in this.text_) { | |||
allWarnings.push(this.text_[id]); | |||
for (const id in this.text) { |
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.
is this for loop different than this.text.values()
? we probably just didn't use it before because of IE? (i know you didn't add this but just wondering)
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.
I think that this.text
should probably become a Map
because it's all internal. @gonfunko was there a specific reason you skipped this when you were updating to Maps?
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, and I also updated tests to use helpers for assertions.
core/icon.ts
Outdated
@@ -175,7 +175,7 @@ export abstract class Icon { | |||
* | |||
* @param _group The icon group. | |||
*/ | |||
protected drawIcon_(_group: Element) {} | |||
protected drawIcon_(_group: SVGGElement) {} |
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.
Good point. I don't think that we do, but it is technically a breaking change so I'll put it back.
core/mutator.ts
Outdated
private resizeBubble_() { | ||
private resizeBubble() { | ||
// If the bubble exists, the workspace also exists. | ||
const ws = this.workspace as WorkspaceSvg; |
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 and done.
core/mutator.ts
Outdated
this.rootBlock_ = block.decompose!(this.workspace_!)!; | ||
const blocks = this.rootBlock_!.getDescendants(false); | ||
this.rootBlock = block.decompose!(this.workspace!)!; | ||
const blocks = this.rootBlock!.getDescendants(false); |
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.
@@ -456,7 +454,7 @@ export class Mutator extends Icon { | |||
block.rendered = false; | |||
|
|||
// Allow the source block to rebuild itself. | |||
block.compose!(this.rootBlock_); | |||
block.compose!(this.rootBlock); |
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.
Yes! I'm not doing it now but I agree that there should be a way to communicate that to the compiler and it would be fancy.
@@ -143,8 +143,8 @@ export class Warning extends Icon { | |||
*/ | |||
getText(): string { | |||
const allWarnings = []; | |||
for (const id in this.text_) { | |||
allWarnings.push(this.text_[id]); | |||
for (const id in this.text) { |
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.
I think that this.text
should probably become a Map
because it's all internal. @gonfunko was there a specific reason you skipped this when you were updating to Maps?
The basics
npm run format
andnpm run lint
The details
Resolves
Part of #6548
Proposed Changes
Remove underscores from private property names and method names, where they weren't being used by tests.
Also cleans up some nullability indicators.
Behavior Before Change
No change.
Behavior After Change
No change.
Reason for Changes
General cleanup, as a way of reading through code and understanding icon architecture.
Test Coverage
Mocha tests, and also opened up the playground and played around with comments and mutators.
Documentation
None.
Additional Information
comment.textarea_
andcomment.paragraphElement_
are being accessed directly in tests, so I left them alone.