-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
require extension option explicitly #13218
Conversation
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, |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
This pull request introduces 1 alert - view on lgtm.com new alerts:
Comment posted by lgtm.com |
gulpfile.js
Outdated
* loadPriority: ?string | ||
* }} | ||
*/ | ||
const ExtensionOption; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
@rsimha-amp The extension I'm working on adds some additional options. While reviewing how to introduce – I noticed this pattern where the @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. |
a0acebf
to
2be24ba
Compare
@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) |
There was a problem hiding this 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.
get rid of thisOrThat pattern (tries to emulate function overloading) in favor of explicit option object requirement.