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

feat(top-app-bar): Convert JS to TypeScript #4397

Merged
merged 11 commits into from
Feb 14, 2019

Conversation

acdvorak
Copy link
Contributor

@acdvorak acdvorak commented Feb 9, 2019

Refs #4225

@codecov-io
Copy link

codecov-io commented Feb 9, 2019

Codecov Report

Merging #4397 into feat/typescript will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##           feat/typescript    #4397      +/-   ##
===================================================
+ Coverage            98.86%   98.93%   +0.06%     
===================================================
  Files                   95       95              
  Lines                 6096     6117      +21     
  Branches               802      806       +4     
===================================================
+ Hits                  6027     6052      +25     
+ Misses                  68       64       -4     
  Partials                 1        1
Impacted Files Coverage Δ
packages/mdc-top-app-bar/foundation.ts 100% <100%> (ø)
packages/mdc-top-app-bar/short/foundation.ts 100% <100%> (ø)
packages/mdc-top-app-bar/fixed/foundation.ts 100% <100%> (ø)
packages/mdc-top-app-bar/standard/foundation.ts 100% <100%> (ø)
packages/mdc-top-app-bar/index.ts 100% <100%> (ø)
packages/mdc-dialog/util.ts 100% <0%> (ø) ⬆️
packages/mdc-drawer/index.js
packages/mdc-drawer/util.js
packages/mdc-drawer/modal/foundation.js
... and 6 more

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 5052ada...e3e9023. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

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

@kfranqueiro kfranqueiro mentioned this pull request Feb 9, 2019
45 tasks
@mdc-web-bot
Copy link
Collaborator

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

@mdc-web-bot
Copy link
Collaborator

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

@mdc-web-bot
Copy link
Collaborator

All 624 screenshot tests passed for commit ebaa080 vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 624 screenshot tests passed for commit d90cf29 vs. feat/typescript! 💯🎉

@moog16 moog16 self-assigned this Feb 12, 2019
packages/mdc-top-app-bar/adapter.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/adapter.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/adapter.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/adapter.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/fixed/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/fixed/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/index.ts Outdated Show resolved Hide resolved

this.scrollHandler_ = () => this.fixedScrollHandler_();
}

init() {
super.init();
this.adapter_.registerScrollHandler(this.scrollHandler_);
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you decide to remove this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's redundant; it already happens in MDCTopAppBarBaseFoundation.

The duplication was actually causing unit tests to fail until I removed this.

@mdc-web-bot
Copy link
Collaborator

All 624 screenshot tests passed for commit c8fc735 vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 624 screenshot tests passed for commit 2a49df9 vs. feat/typescript! 💯🎉

packages/mdc-top-app-bar/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-top-app-bar/index.ts Outdated Show resolved Hide resolved
getViewportScrollY: () => {
const win = this.scrollTarget_ as Window;
const el = this.scrollTarget_ as Element;
return win.pageYOffset !== undefined ? win.pageYOffset : el.scrollTop;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this switched from a direct comparison to window to a duck-type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To make it more unit-testing friendly. Direct === comparisons and instanceof checks make it harder to mock things, especially if/when we convert the tests themselves to TypeScript.

packages/mdc-top-app-bar/short/foundation.ts Outdated Show resolved Hide resolved
registerScrollHandler: (handler) => this.scrollTarget_.addEventListener('scroll', handler),
deregisterScrollHandler: (handler) => this.scrollTarget_.removeEventListener('scroll', handler),
notifyNavigationIconClicked: () => this.emit(strings.NAVIGATION_EVENT, {}),
registerScrollHandler: (handler) => this.scrollTarget_.addEventListener('scroll', handler as EventListener),
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to cast them to EventListeners here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing them throws an error:

[tsl] ERROR in packages/mdc-top-app-bar/index.ts(92,89)
      TS2345: Argument of type 'SpecificEventListener<"scroll">' is not assignable to parameter of type 'EventListener | EventListenerObject | null'.
  Type 'SpecificEventListener<"scroll">' is not assignable to type 'EventListener'.
    Types of parameters 'evt' and 'evt' are incompatible.
      Type 'Event' is missing the following properties from type 'UIEvent': detail, view, initUIEvent

That's because scrollTarget_ is an EventTarget rather than an Element, and EventTarget doesn't have generic signatures for addEventListener() or removeEventListener() in lib.dom.d.ts (whereas Element does).

Copy link
Contributor

Choose a reason for hiding this comment

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

I see - its because we need to set scrollTarget to EventTarget - mainly because it could be the Window.

@mdc-web-bot
Copy link
Collaborator

All 624 screenshot tests passed for commit e3e9023 vs. feat/typescript! 💯🎉

Copy link
Contributor

@kfranqueiro kfranqueiro left a comment

Choose a reason for hiding this comment

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

One reminder (I think) for #4407, otherwise LGTM

this.iconRipples_;
/** @type {Object} */
this.scrollTarget_;
export type MDCRippleFactory = (el: Element) => MDCRipple;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this will end up removed in #4407 after this is merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct 😀 Thanks for the reminder!

@acdvorak acdvorak merged commit b8b1988 into feat/typescript Feb 14, 2019
@acdvorak acdvorak deleted the feat/typescript--top-app-bar branch February 14, 2019 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants