Skip to content

refactor: convert row.js and base.js to ES6 classes #5957

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

Merged
merged 7 commits into from
Feb 25, 2022

Conversation

BeksOmega
Copy link
Contributor

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide

The details

Resolves

Last of #5860

Proposed Changes

There were some places where extra properties were getting assigned to Row instances. This moves them into WeakMaps instead because they are only used by certain subclass renderers.

I also added a lot of instanceof checks for row elements to fix type errors. But I left the Type.isX() calls as well. Not sure if we want to remove those or not.

Should be no change in behavior 🤞

Reason for Changes

The long winding journey to TypeScript

Test Coverage

Sanity checked that all renderers look correct.

Tested on:

  • Desktop Chrome

Documentation

N/A

Additional Information

N/A

@BeksOmega BeksOmega requested a review from a team as a code owner February 23, 2022 23:45
@BeksOmega BeksOmega requested a review from cpcallen February 23, 2022 23:45
@BeksOmega
Copy link
Contributor Author

I think removing that property assignment in the most recent commit is fine. It was added in #3740 to fix the bounding boxes of blocks, but I don't think it actually did that. I removed the assignment and bounding boxes still look fine:

image

Copy link
Contributor

@cpcallen cpcallen left a comment

Choose a reason for hiding this comment

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

Looks good to me. I will leave final approval to @rachel-fenichel, once she has looked at the statementEdge question.

Comment on lines +153 to +154
} else if (
Types.isPreviousConnection(elem) && elem instanceof Connection) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming that Types.isPreviousConnection(elem) implies that elem instanceof Connection and you're just helping the compiler figure that out, but if that's not so beware that this could result in a change of behaviour, where cases that would previously have matched this if clause could end up falling through and potentially matching later ones.

A slightly more conservative approach to adding a type check here would be:

      } else if (Types.isPreviousConnection(elem)) {
        if(!(elem instanceof Connection)) throw new TypeError(/*...*/);

(Here and various other places.)

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'm pretty sure that these instanceof checks shouldn't modify behavior, especially because we rely on properties of the checked class existing.

Honestly, I'm not sure why Types exists at all. It looks like it was meant to unify a bunch of ad-hoc "type" checks. But it seems like instanceof works just as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just bumping this to check your opinion before merging @cpcallen

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM.

@BeksOmega BeksOmega merged commit 237e66c into google:develop Feb 25, 2022
@BeksOmega BeksOmega deleted the refact/rows-to-es6 branch April 5, 2022 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants