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

refactor: foregroundChild arguments normalization #25

Merged
merged 1 commit into from
Sep 20, 2018

Conversation

demurgos
Copy link
Contributor

Why

foregroundChild has a complex signature. Using a dedicated function for arguments normalization would improve clarity.

What

Document the signature of foregroundChild, move arguments normalization to a separate function, small simplification to the normalization.

@demurgos demurgos force-pushed the refactor-arguments-normalization branch from 6c0acb9 to ac478ce Compare September 19, 2018 06:45
@demurgos
Copy link
Contributor Author

demurgos commented Sep 19, 2018

The CI failure seems to be an Appveyor issue (issue in their npm package). Fixed in #24.

@demurgos
Copy link
Contributor Author

This also fixes a bug: #30 (comment)

Copy link

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

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

Just nitpicks.

index.js Outdated
var lastFgArg = fgArgs[fgArgs.length - 1];
if (typeof lastFgArg === "function") {
cb = lastFgArg;
processArgsEnd--;

Choose a reason for hiding this comment

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

Prefer use of -= 1 instead for explicitness.

Copy link
Contributor Author

@demurgos demurgos Sep 19, 2018

Choose a reason for hiding this comment

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

Should I push force the update or use an extra commit to address this?

} else if (!Array.isArray(args)) {
args = [].slice.call(arguments, 1, arrayIndex)
}
return {program: program, args: args, cb: cb};

Choose a reason for hiding this comment

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

Since we're doing ES6, this could just be:

return { program, args, cb };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, no ES6 for the moment. But yeah, I used object short hand originally.
I'll send a follow-up PR to move to ES6.

* ```
*/
module.exports = function (/* program, args, cb */) {
var fgArgs = normalizeFgArgs([].slice.call(arguments, 0));

Choose a reason for hiding this comment

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

Why not just Array.from(arguments) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what was used originally. I plan to move to ES6 later anyway, where it'll simply become function(...fgArgs).

Choose a reason for hiding this comment

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

Ok...

@demurgos demurgos force-pushed the refactor-arguments-normalization branch 2 times, most recently from 4b2371c to 244e8e1 Compare September 20, 2018 22:45
# Why

`foregroundChild` has a complex signature. Using a dedicated function for arguments normalization would improve clarity.

# What

Document the signature of `foregroundChild`, move arguments normalization to a separate function, small simplification to the normalization.
@demurgos demurgos force-pushed the refactor-arguments-normalization branch from 244e8e1 to afc1466 Compare September 20, 2018 22:57
@bcoe
Copy link
Member

bcoe commented Sep 20, 2018

@demurgos this seems reasonable to me, do we have tests already for each function signature?

@demurgos
Copy link
Contributor Author

demurgos commented Sep 20, 2018

@bcoe See #30

@bcoe bcoe merged commit 489ec00 into tapjs:master Sep 20, 2018
@demurgos demurgos deleted the refactor-arguments-normalization branch September 20, 2018 23:34
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

3 participants