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

require extension option explicitly #13218

Merged

Conversation

erwinmombay
Copy link
Member

@erwinmombay erwinmombay commented Feb 1, 2018

get rid of thisOrThat pattern (tries to emulate function overloading) in favor of explicit option object requirement.

@rsimha
Copy link
Contributor

rsimha commented Feb 1, 2018

Why was this PR necessary? Can you add a description?

gulpfile.js Outdated
function declareExtension(name, version, options) {
const defaultOptions = {hasCss: false};
const extensionKey = `${name}-${version}`;
extensions[extensionKey] = Object.assign({
name: name,
version: version,
hasCss: hasCss,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove this line, hasCss isn't available anymore in this scope!

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks!

gulpfile.js Outdated
function declareExtension(name, version, options) {
const defaultOptions = {hasCss: false};
const extensionKey = `${name}-${version}`;
extensions[extensionKey] = Object.assign({
name: name,
Copy link
Contributor

Choose a reason for hiding this comment

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

No requirement here, but can leverage Shorthand property names.

Object.assign({
  name,
  version,
}, defaultOptions, options);

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@cramforce
Copy link
Member

This pull request introduces 1 alert - view on lgtm.com

new alerts:

  • 1 for Syntax error

Comment posted by lgtm.com

gulpfile.js Outdated
* loadPriority: ?string
* }}
*/
const ExtensionOption;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a leftover const definition. Mind removing?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is required for jscompiler typechecking (it needs a reference to an identifier)

@kristoferbaxter
Copy link
Contributor

@rsimha-amp The extension I'm working on adds some additional options. While reviewing how to introduce – I noticed this pattern where the declareExtension function was inspecting the type the third argument was and then adapting to it.

@erwinmombay and I chatted about it and didn't see a reason why it should do this instead of passing a known typed argument. This PR is the result of that conversation.

@erwinmombay
Copy link
Member Author

@rsimha-amp I'm just not a fan of the thisTypeOrAnotherType pattern (because javascript doesn't have method/function overloading). Unions are also OK but but this one tries to emulate method overloading instead which always turns ugly logically. (just look at the If else logic we had to remove)

Copy link
Contributor

@rsimha rsimha left a comment

Choose a reason for hiding this comment

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

Aha, makes sense! Can you move that explanation to the PR description? It's useful to say what you're doing in a PR at the very top so that others reading this later know what's going on.

@erwinmombay erwinmombay merged commit 9abef74 into ampproject:master Feb 1, 2018
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
protonate pushed a commit to protonate/amphtml that referenced this pull request Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants