Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(snackbar): Convert JS to TypeScript #4363

Merged
merged 10 commits into from
Feb 9, 2019

Conversation

acdvorak
Copy link
Contributor

@acdvorak acdvorak commented Feb 7, 2019

Refs #4225

@codecov-io
Copy link

codecov-io commented Feb 7, 2019

Codecov Report

Merging #4363 into feat/typescript will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##           feat/typescript    #4363      +/-   ##
===================================================
+ Coverage            98.65%   98.65%   +<.01%     
===================================================
  Files                   93       93              
  Lines                 5930     5947      +17     
  Branches               797      795       -2     
===================================================
+ Hits                  5850     5867      +17     
  Misses                  79       79              
  Partials                 1        1
Impacted Files Coverage Δ
packages/mdc-snackbar/util.ts 100% <100%> (ø)
packages/mdc-snackbar/index.ts 100% <100%> (ø)
packages/mdc-snackbar/foundation.ts 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08fb283...ad978e3. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 5bfb6be vs. feat/typescript! 💯🎉

this.surfaceEl_ = /** @type {!HTMLElement} */ (this.root_.querySelector(SURFACE_SELECTOR));
this.labelEl_ = /** @type {!HTMLElement} */ (this.root_.querySelector(LABEL_SELECTOR));
this.actionEl_ = /** @type {!HTMLElement} */ (this.root_.querySelector(ACTION_SELECTOR));
this.surfaceEl_ = this.root_.querySelector<HTMLElement>(SURFACE_SELECTOR)!;
Copy link
Contributor

Choose a reason for hiding this comment

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

We're casting to HTMLElement here but defining these as Element above? If they were already safely HTMLElement in the original implementation, then we can probably preserve that... either way, should we be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed HTMLElement generic type param

packages/mdc-snackbar/util.ts Outdated Show resolved Hide resolved
* @param {!MouseEvent} evt
*/
handleActionButtonClick(evt) {
handleActionButtonClick(_evt: MouseEvent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove this argument since you're not using it?

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 considered doing removing it, but I thought it would be more future-proof to keep it.

If we end up needing to inspect the event object in the future—e.g., to avoid taking an action if the shift/meta keys are pressed—we won't need to introduce a breaking change, because we'll already have access to the event.

Removing the param would technically be a breaking change too, so we'd have to create a separate PR to make the change in master as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah... from the perspective of this being a straight conversion, might as well leave it, since I guess it was unused even on master then, right?

this.surfaceEl_ = /** @type {!HTMLElement} */ (this.root_.querySelector(SURFACE_SELECTOR));
this.labelEl_ = /** @type {!HTMLElement} */ (this.root_.querySelector(LABEL_SELECTOR));
this.actionEl_ = /** @type {!HTMLElement} */ (this.root_.querySelector(ACTION_SELECTOR));
this.surfaceEl_ = this.root_.querySelector<HTMLElement>(SURFACE_SELECTOR)!;
Copy link
Contributor

Choose a reason for hiding this comment

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

I also notice you're ! to each querySelector call. Should we throw an error if they don't exist?

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 think we normally avoid throwing errors for required elements, except in very specific circumstances where it's easy for clients to make a mistake and hard for them to figure out what caused it.

E.g., modal/dismissible drawers need a scrim element, whereas permanent drawers lack one. If a client decides to switch from a permanent drawer to a dismissible drawer, they could very easily forget to add the scrim element, so a descriptive error message is really helpful.

This case is a little more straightforward because all the elements are always required.

Personally, I wouldn't be opposed to throwing errors for all missing elements, but we probably shouldn't make that change in this PR; we'd want to do that across all packages for consistency.

packages/mdc-snackbar/index.ts Show resolved Hide resolved
@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 541b4e4 vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 4d06fd5 vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 9fd3bce vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit ad978e3 vs. feat/typescript! 💯🎉

@acdvorak acdvorak merged commit e95ff8a into feat/typescript Feb 9, 2019
@acdvorak acdvorak deleted the feat/typescript--snackbar branch February 9, 2019 00:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants