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

Default to array #34

Merged
merged 1 commit into from
Aug 31, 2015
Merged

Default to array #34

merged 1 commit into from
Aug 31, 2015

Conversation

a-b-r-o-w-n
Copy link
Contributor

fixes #22

it('can create array if all keys are numbers', () => {
const result = u.updateIn('a.1', 3, null);

expect(result).to.eql({ a: [, 3] });
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 leaves the linter unhappy, but I am not sure how to test this. Creating a new array and setting a value at an index i where i is greater than array.length results in some an array with some elements missing (docs). This seems fine from an application level, but testing it in this way makes the linter unhappy.

Should I just disable the linter warnings for this line?

Copy link
Member

Choose a reason for hiding this comment

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

does [undefined, 3] pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't.

@aaronjensen
Copy link
Member

This looks, good, once you get stuff passing can you rebase into a single commit and update the readme/changelog too? Thanks!

@a-b-r-o-w-n a-b-r-o-w-n force-pushed the default-to-array branch 2 times, most recently from 2bd6ae6 to c33ae8f Compare August 30, 2015 23:39
it('can create array if all keys are numbers', () => {
const result = u.updateIn('a.1', 3, null);

expect(result).to.eql({ a: [, 3] }); // eslint-disable-line no-sparse-arrays
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm actually surprised that this is valid syntax. It's not pretty though. Another option would be:

expect(result.a[1]).to.eql(3);

Copy link
Member

Choose a reason for hiding this comment

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

well, you'd also need to test that it is an array if you did that. You could also just use the 0 index. I'm good w/ any of these (including what you did)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do 0 index

a-b-r-o-w-n pushed a commit that referenced this pull request Aug 31, 2015
@a-b-r-o-w-n a-b-r-o-w-n merged commit 12bf952 into master Aug 31, 2015
@a-b-r-o-w-n a-b-r-o-w-n deleted the default-to-array branch August 31, 2015 00:00
aaronjensen added a commit that referenced this pull request Nov 16, 2015
This reverts commit 12bf952, reversing
changes made to 7a35404.
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.

Default to array instead of object if all update keys are numbers
2 participants