Skip to content

Commit

Permalink
Change function’s arguments signature (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Feb 14, 2017
1 parent 45d5e5e commit 500d7d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Day.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function handleEvent(handler, day, modifiers) {
}
return (e) => {
e.persist();
handler(e, day, modifiers);
handler(day, modifiers, e);
};
}
export default function Day({
Expand Down
10 changes: 5 additions & 5 deletions src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export default class DayPicker extends Component {
}
}

handleDayKeyDown(e, day, modifiers) {
handleDayKeyDown(day, modifiers, e) {
e.persist();
switch (e.keyCode) {
case keys.LEFT:
Expand All @@ -319,23 +319,23 @@ export default class DayPicker extends Component {
case keys.SPACE:
Helpers.cancelEvent(e);
if (this.props.onDayClick) {
this.handleDayClick(e, day, modifiers);
this.handleDayClick(day, modifiers, e);
}
break;
default:
break;
}
if (this.props.onDayKeyDown) {
this.props.onDayKeyDown(e, day, modifiers);
this.props.onDayKeyDown(day, modifiers, e);
}
}

handleDayClick(e, day, modifiers) {
handleDayClick(day, modifiers, e) {
e.persist();
if (modifiers.outside) {
this.handleOutsideDayClick(day);
}
this.props.onDayClick(e, day, modifiers);
this.props.onDayClick(day, modifiers, e);
}

handleOutsideDayClick(day) {
Expand Down
2 changes: 1 addition & 1 deletion src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function Month({
months,
localeUtils,
locale,
onClick: onCaptionClick ? e => onCaptionClick(e, month) : undefined,
onClick: onCaptionClick ? e => onCaptionClick(month, e) : undefined,
};
const weeks = getWeekArray(month, firstDayOfWeek, fixedWeeks);
return (
Expand Down
11 changes: 7 additions & 4 deletions test/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,11 @@ describe('<DayPicker />', () => {
const wrapper = mount(<DayPicker onCaptionClick={ handleCaptionClick } />);
wrapper.find('.DayPicker-Caption').simulate('click');
expect(handleCaptionClick).to.have.been.calledWith(
sinon.match(date =>
date.getFullYear() === (new Date()).getFullYear() && date.getMonth() === (new Date()).getMonth(),
'currentMonth',
),
sinon.match(e => e instanceof SyntheticEvent && e.target !== null, 'e'),
sinon.match(date => date.getFullYear() === (new Date()).getFullYear() && date.getMonth() === (new Date()).getMonth(), 'currentMonth'),
);
});
it('should call the day\'s cell event handlers', () => {
Expand All @@ -585,9 +588,9 @@ describe('<DayPicker />', () => {
);

const eventArgs = [
sinon.match(e => e instanceof SyntheticEvent && e.target !== null, 'e'),
sinon.match(date => date.getFullYear() === (new Date()).getFullYear() && date.getMonth() === (new Date()).getMonth(), 'currentMonth'),
sinon.match(mods => mods.foo, 'modifiers'),
sinon.match(e => e instanceof SyntheticEvent && e.target !== null, 'e'),
];

wrapper.find('.DayPicker-Day--foo').simulate('click');
Expand Down Expand Up @@ -640,9 +643,9 @@ describe('<DayPicker />', () => {
/>,
);
const eventArgs = [
sinon.match(e => e instanceof SyntheticEvent && e.target !== null, 'e'),
sinon.match(date => date.getFullYear() === (new Date()).getFullYear() && date.getMonth() === (new Date()).getMonth(), 'currentMonth'),
sinon.match(mods => mods.foo && !mods.bar, 'modifiers'),
sinon.match(e => e instanceof SyntheticEvent && e.target !== null, 'e'),
];
wrapper.find('.DayPicker-Day--foo').simulate('keyDown', { keyCode: keys.ENTER });
expect(handleDayClick).to.have.been.calledWith(...eventArgs);
Expand All @@ -657,9 +660,9 @@ describe('<DayPicker />', () => {
/>,
);
const eventArgs = [
sinon.match(e => e instanceof SyntheticEvent && e.target !== null, 'e'),
sinon.match(date => date.getFullYear() === (new Date()).getFullYear() && date.getMonth() === (new Date()).getMonth(), 'currentMonth'),
sinon.match(mods => mods.foo, 'modifiers'),
sinon.match(e => e instanceof SyntheticEvent && e.target !== null, 'e'),
];
wrapper.find('.DayPicker-Day--foo').simulate('keyDown', { keyCode: keys.SPACE });
expect(handleDayClick).to.have.been.calledWith(...eventArgs);
Expand Down

0 comments on commit 500d7d2

Please sign in to comment.