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 duplicate months #279

Merged
merged 2 commits into from
Feb 1, 2017
Merged

Conversation

moonboots
Copy link
Collaborator

to: @majapw @ljharb

This PR fixes two issues related to duplicate months in CalendarMonthGrid:

  • When increasing numberOfMonths, the last month was duplicated in the first iteration of this loop. I simplified to reuse the getMonths logic instead of updating piecemeal. This should only be called when numberOfMonths changes, and it shouldn't affect the original perf improvements.
  • Include year in CalendarMonth key to allow more than 12 months. Otherwise, React will only render the first occurrence and print Warning: flattenChildren(...): Encountered two children with the same key.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.2%) to 87.349% when pulling 75f5812 on moonboots:fix-month-conflict into 0bd7072 on airbnb:master.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

LGTM pending one comment

const collisions = months
.map(m => m.format('YYYY-MM'))
.reduce((acc, m) => Object.assign(
{}, acc, { [m]: true }
Copy link
Member

Choose a reason for hiding this comment

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

if the invocation parens and every argument can't fit on one line, then each argument must be on a line by itself.

@ljharb ljharb added the semver-patch: fixes/refactors/etc Anything that's not major or minor. label Feb 1, 2017
} else {
newMonths = months.slice(0, numberOfMonths + 3);
}
newMonths = getMonths(initialMonth, numberOfMonths);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically, I think the reason for this was to not create hella new moment objects when you changed the number of months which I think getMonths does, but I suppose that's a fairly rare edgecase.

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

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

Seems legit to me after Jordan's comment has been addressed and tests/linting is addressed

@moonboots
Copy link
Collaborator Author

Thanks, fixed the lint and spec issues, ptal

@coveralls
Copy link

Coverage Status

Coverage increased (+2.3%) to 86.908% when pulling 671dea3 on moonboots:fix-month-conflict into 7ce9681 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.3%) to 86.908% when pulling 671dea3 on moonboots:fix-month-conflict into 7ce9681 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.3%) to 86.908% when pulling 671dea3 on moonboots:fix-month-conflict into 7ce9681 on airbnb:master.

@moonboots moonboots merged commit a7eeda2 into react-dates:master Feb 1, 2017
@moonboots moonboots deleted the fix-month-conflict branch February 1, 2017 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch: fixes/refactors/etc Anything that's not major or minor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants