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

use rest parameters instead of arguments #1524

Merged
merged 2 commits into from
Jan 26, 2017
Merged

use rest parameters instead of arguments #1524

merged 2 commits into from
Jan 26, 2017

Conversation

brendankenny
Copy link
Member

enabled now that we have node v6 as the baseline.

sorry @ebidel, got to it first :)

@ebidel
Copy link
Contributor

ebidel commented Jan 25, 2017

yes
Yes
YES

*/
issueStatus(title, args) {
issueStatus(title, ...args) {
if (title === 'status' || title === 'statusEnd') {
this.emit(title, args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't this stick all current args in an array? will that impact anything outside of changed below?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. Kind of confusingly args was previously an array, and event consumers are expecting a single array from the event, but that made it awkward to call when switching everything else to rest params, so it was easiest to just have varargs and group them up into an array here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah ok

return Log._logToStdErr(title, Array.from(arguments).slice(1));
static log(title, ...args) {
Log.events.issueStatus(title, ...args);
return Log._logToStdErr(title, args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

_logToStdErr doesn't seem to have been changed at all did it already support this?

Copy link
Member Author

Choose a reason for hiding this comment

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

_logToStdErr doesn't seem to have been changed at all did it already support this?

Maybe I'm misunderstanding you, but isn't this right? args is an array of all but the first argument, equivalent to the old Array.from(arguments).slice(1))?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, no I just misread the diff thinking it didn't have a second argument at all, disregard :)

console.log = function() {
ConsoleQuieter._logs.push({type: 'log', args: arguments, prefix: opts.prefix});
console.log = function(...args) {
ConsoleQuieter._logs.push({type: 'log', args: args, prefix: opts.prefix});
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can just do {type: 'log', args,

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

now possible by dropping support for node older than v6
Log.events.issueStatus(title, arguments);
return Log._logToStdErr(title, Array.from(arguments).slice(1));
static log(title, ...args) {
Log.events.issueStatus(title, ...args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is one difference with the previous code block.
...args doesn't contain title whereas arguments did.
to fix you should do issueStatus(title, [title, ...args])

Copy link
Member Author

Choose a reason for hiding this comment

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

ugh, I looked at this, thought it was terrible but had to be maintained, then promptly forgot about it, apparently. Thanks :)

}

static verbose(title) {
static verbose(title, ...args) {
Log.events.issueStatus(title);
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comment above about arguments, ...args inside the function will be an empty []

Copy link
Member Author

Choose a reason for hiding this comment

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

See comment above about arguments, ...args inside the function will be an empty []

I don't think that applies here since it's only doing Log.events.issueStatus(title), so it gets an empty array on master already.

Honestly I have no idea why it's doing issueStatus here with no args anyways. It doesn't make much sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

looks like it was a bug introduced in 71195e4#diff-e5b0c339f7ea6da4ec03ff079a28288cL100 I'll fix.

also reduces rest/spread repetitions
@brendankenny
Copy link
Member Author

updated (see second commit). Also reduced some of the ridiculous repetitions of rest/spread/rest/spread :)

@paulirish paulirish merged commit 4abb2db into master Jan 26, 2017
@paulirish paulirish deleted the restparams branch January 26, 2017 23:52
@ebidel
Copy link
Contributor

ebidel commented Jan 27, 2017

😴 + ⛳️ + 🐏 s

paulirish pushed a commit to paulirish/lighthouse that referenced this pull request Jan 27, 2017
* use rest parameters instead of arguments

now possible by dropping support for node older than v6

* fix status event payload

also reduces rest/spread repetitions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants