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

[Fix] reduce/reduceRight: follow Array#reduce when omitting initialValue #673

Merged
merged 1 commit into from
Sep 1, 2017

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Nov 11, 2016

Closes #667.

I've marked this as a patch - but it might potentially be breaking if someone was relying on omitting the required (incorrectly documented as optional) initialValue being undefined.

Thoughts?

Copy link
Contributor

@blainekasten blainekasten left a comment

Choose a reason for hiding this comment

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

Are we not liking the idea of running up major versions? In my mind versions are cheap, and bumping a major just to be safe is never a bad idea.

(accum, n, i) => fn.call(this, accum, this.wrap(n), i),
initialValue,
);
reduce(fn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we maybe add the old argument back within comment blocks so we see that it is part of the API. Yes jsdoc helps above, but it gets a bit confusing when see this and then L729

Copy link
Contributor

Choose a reason for hiding this comment

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

same for the reduceRight

Copy link
Collaborator

@aweary aweary Nov 11, 2016

Choose a reason for hiding this comment

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

I believe @ljharb is trying to preserve the correct .length property on the function, which should only count required arguments. I think elsewhere we just use a default value of undefined, which might be good here.

reduce(fn, initialValue = undefined) {

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't do that because the native reduce/reduceRight distinguish between undefined and "absent" - or rather, id still have to check arguments.length and ignore initialValue when arguments.length is < 2

Copy link
Contributor

Choose a reason for hiding this comment

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

yes yes, i was merely suggesting this: reduce(fn /*, initialValue */) { ... }

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll do one of the two - as long as the behavior and function length are correct, I'm happy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@ljharb
Copy link
Member Author

ljharb commented Nov 11, 2016

@blainekasten bumping versions is indeed cheap, but it's nice to avoid bumping majors because of semver ranges.

@blainekasten
Copy link
Contributor

I think it's smarter to prevent code from breaking without users expecting it than to worry users will be on old versions of enzyme due to ranges..

@ljharb ljharb added semver: major Breaking changes and removed semver: patch labels Nov 12, 2016
Copy link
Collaborator

@nfcampos nfcampos left a comment

Choose a reason for hiding this comment

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

Looks great!

@ljharb ljharb force-pushed the fix_reduce branch 3 times, most recently from e5e4f64 to d45ee73 Compare March 20, 2017 01:50
@nfcampos
Copy link
Collaborator

@ljharb should we get this in for v3?

@ljharb
Copy link
Member Author

ljharb commented Aug 31, 2017

@nfcampos good call; I'll rebase.

@ljharb ljharb merged commit d16c8ed into enzymejs:master Sep 1, 2017
@ljharb ljharb deleted the fix_reduce branch September 1, 2017 00:05
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.

4 participants