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

chore: remove some underscores in icon-related classes #6583

Merged
merged 5 commits into from Oct 31, 2022

Conversation

rachel-fenichel
Copy link
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm 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_ and comment.paragraphElement_ are being accessed directly in tests, so I left them alone.

@rachel-fenichel rachel-fenichel requested a review from a team as a code owner October 26, 2022 22:28
@github-actions github-actions bot added the PR: chore General chores (dependencies, typos, etc) label Oct 26, 2022
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}`);
Copy link
Contributor

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

Copy link
Collaborator Author

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) {}
Copy link
Contributor

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.

Copy link
Collaborator Author

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');
Copy link
Contributor

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?

Copy link
Collaborator Author

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;
Copy link
Contributor

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

Copy link
Collaborator Author

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);
Copy link
Contributor

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

Copy link
Collaborator Author

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);
Copy link
Contributor

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

Copy link
Collaborator Author

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) {
Copy link
Contributor

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)

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

@rachel-fenichel rachel-fenichel left a 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) {}
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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?

@rachel-fenichel rachel-fenichel merged commit f95af36 into google:develop Oct 31, 2022
@rachel-fenichel rachel-fenichel deleted the comment_cleanup branch October 31, 2022 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: chore General chores (dependencies, typos, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants