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

Accept an options object in scroll method #39

Merged
merged 4 commits into from
Apr 3, 2018

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Mar 31, 2018

Part of polymer/gen-typescript-declarations#79.

An element mixing in this behaviour won't compile in TypeScript because our definition of the scroll method incorrectly overrides the base one that Element has.

To resolve this, i've added an options object to match the built in scroll method.

I also re-ran gen-tsd.

cc @aomarks

@43081j 43081j requested a review from keanulee as a code owner March 31, 2018 17:44
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot
Copy link

CLAs look good, thanks!

@@ -189,15 +189,21 @@
* Scrolls the content to a particular place.
*
* @method scroll
* @param {number} left The left position
* @param {number} top The top position
* @param {number|!ScrollToOptions} leftOrOptions The left position or scroll options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI (especially @aomarks) i dont think theres a way (yet, if ever) to specify overloads. so technically scroll(obj, 1) is valid according to this. not a lot we can do about that as jsdoc/closure types don't seem to have any such way

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, pretty sure there's no way to describe that to Closure.

window.scrollTo(left, top);
scroll: function(leftOrOptions, top) {
var opts = leftOrOptions;
if (typeof leftOrOptions !== 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe unpack the options into a left/top var if present, instead of always allocating this object.

* @param top The top position
*/
scroll(left: number, top: number): void;
scroll(leftOrOptions: number|ScrollToOptions, top?: number): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is ScrollToOptions a type Closure already has?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its a type the spec (and thus typescript) has, but im not too sure if closure knows of it or not. if it doesn't, it should :p

@aomarks
Copy link
Contributor

aomarks commented Apr 3, 2018

This looks good to me, @keanulee can you give it a look too?


if (typeof leftOrOptions === 'object') {
left = leftOrOptions.x;
top = leftOrOptions.y;
Copy link
Contributor

Choose a reason for hiding this comment

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

The first arg of type ScrollToOptions should contain left and top , not x and y

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so it is. no clue where i pulled x/y from, in my initial code of this it was left/top 🙄

@43081j
Copy link
Contributor Author

43081j commented Apr 3, 2018

@keanulee here you go. resolved that issue

@keanulee keanulee merged commit d2313f4 into PolymerElements:master Apr 3, 2018
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.

4 participants