Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit a60f34d

Browse files
committed
Remove bind expressions
1 parent 732916f commit a60f34d

File tree

6 files changed

+53
-80
lines changed

6 files changed

+53
-80
lines changed

src/components/Calendar/index.js

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,6 @@ import coreStyles from '../../styles';
3131
class Calendar extends PureComponent {
3232
constructor(props, context) {
3333
super(props, context);
34-
this.changeShownDate = this.changeShownDate.bind(this);
35-
this.focusToDate = this.focusToDate.bind(this);
36-
this.updateShownDate = this.updateShownDate.bind(this);
37-
this.handleRangeFocusChange = this.handleRangeFocusChange.bind(this);
38-
this.renderDateDisplay = this.renderDateDisplay.bind(this);
39-
this.onDragSelectionStart = this.onDragSelectionStart.bind(this);
40-
this.onDragSelectionEnd = this.onDragSelectionEnd.bind(this);
41-
this.onDragSelectionMove = this.onDragSelectionMove.bind(this);
42-
this.renderMonthAndYear = this.renderMonthAndYear.bind(this);
43-
this.updatePreview = this.updatePreview.bind(this);
44-
this.estimateMonthSize = this.estimateMonthSize.bind(this);
45-
this.handleScroll = this.handleScroll.bind(this);
4634
this.dateOptions = { locale: props.locale };
4735
if (this.props.weekStartsOn !== undefined)
4836
this.dateOptions.weekStartsOn = this.props.weekStartsOn;
@@ -82,7 +70,7 @@ class Calendar extends PureComponent {
8270
calendarHeight: longMonthHeight || 300,
8371
};
8472
}
85-
focusToDate(date, props = this.props, preventUnnecessary = true) {
73+
focusToDate = (date, props = this.props, preventUnnecessary = true) => {
8674
if (!props.scroll.enabled) {
8775
this.setState({ focusedDate: date });
8876
return;
@@ -93,8 +81,8 @@ class Calendar extends PureComponent {
9381
this.isFirstRender = true;
9482
this.list.scrollTo(targetMonthIndex);
9583
this.setState({ focusedDate: date });
96-
}
97-
updateShownDate(props = this.props) {
84+
};
85+
updateShownDate = (props = this.props) => {
9886
const newProps = props.scroll.enabled
9987
? {
10088
...props,
@@ -103,8 +91,8 @@ class Calendar extends PureComponent {
10391
: props;
10492
const newFocus = calcFocusDate(this.state.focusedDate, newProps);
10593
this.focusToDate(newFocus, newProps);
106-
}
107-
updatePreview(val) {
94+
};
95+
updatePreview = val => {
10896
if (!val) {
10997
this.setState({ preview: null });
11098
return;
@@ -115,7 +103,7 @@ class Calendar extends PureComponent {
115103
color: this.props.color,
116104
};
117105
this.setState({ preview });
118-
}
106+
};
119107
componentDidMount() {
120108
if (this.props.scroll.enabled) {
121109
// prevent react-list's initial render focus problem
@@ -150,7 +138,7 @@ class Calendar extends PureComponent {
150138
}
151139
}
152140

153-
changeShownDate(value, mode = 'set') {
141+
changeShownDate = (value, mode = 'set') => {
154142
const { focusedDate } = this.state;
155143
const { onShownDateChange, minDate, maxDate } = this.props;
156144
const modeMapper = {
@@ -163,11 +151,11 @@ class Calendar extends PureComponent {
163151
const newDate = min([max([modeMapper[mode](), minDate]), maxDate]);
164152
this.focusToDate(newDate, this.props, false);
165153
onShownDateChange && onShownDateChange(newDate);
166-
}
167-
handleRangeFocusChange(rangesIndex, rangeItemIndex) {
154+
};
155+
handleRangeFocusChange = (rangesIndex, rangeItemIndex) => {
168156
this.props.onRangeFocusChange && this.props.onRangeFocusChange([rangesIndex, rangeItemIndex]);
169-
}
170-
handleScroll() {
157+
};
158+
handleScroll = () => {
171159
const { onShownDateChange, minDate } = this.props;
172160
const { focusedDate } = this.state;
173161
const { isFirstRender } = this;
@@ -182,8 +170,8 @@ class Calendar extends PureComponent {
182170
onShownDateChange && onShownDateChange(visibleMonth);
183171
}
184172
this.isFirstRender = false;
185-
}
186-
renderMonthAndYear(focusedDate, changeShownDate, props) {
173+
};
174+
renderMonthAndYear = (focusedDate, changeShownDate, props) => {
187175
const { showMonthArrow, minDate, maxDate, showMonthAndYearPickers } = props;
188176
const upperYearLimit = (maxDate || Calendar.defaultProps.maxDate).getFullYear();
189177
const lowerYearLimit = (minDate || Calendar.defaultProps.minDate).getFullYear();
@@ -244,7 +232,7 @@ class Calendar extends PureComponent {
244232
) : null}
245233
</div>
246234
);
247-
}
235+
};
248236
renderWeekdays() {
249237
const now = new Date();
250238
return (
@@ -260,7 +248,7 @@ class Calendar extends PureComponent {
260248
</div>
261249
);
262250
}
263-
renderDateDisplay() {
251+
renderDateDisplay = () => {
264252
const {
265253
focusedRange,
266254
color,
@@ -316,8 +304,8 @@ class Calendar extends PureComponent {
316304
})}
317305
</div>
318306
);
319-
}
320-
onDragSelectionStart(date) {
307+
};
308+
onDragSelectionStart = date => {
321309
const { onChange, dragSelectionEnabled } = this.props;
322310

323311
if (dragSelectionEnabled) {
@@ -331,9 +319,9 @@ class Calendar extends PureComponent {
331319
} else {
332320
onChange && onChange(date);
333321
}
334-
}
322+
};
335323

336-
onDragSelectionEnd(date) {
324+
onDragSelectionEnd = date => {
337325
const { updateRange, displayMode, onChange, dragSelectionEnabled } = this.props;
338326

339327
if (!dragSelectionEnabled) return;
@@ -353,8 +341,8 @@ class Calendar extends PureComponent {
353341
updateRange && updateRange(newRange);
354342
});
355343
}
356-
}
357-
onDragSelectionMove(date) {
344+
};
345+
onDragSelectionMove = date => {
358346
const { drag } = this.state;
359347
if (!drag.status || !this.props.dragSelectionEnabled) return;
360348
this.setState({
@@ -364,9 +352,9 @@ class Calendar extends PureComponent {
364352
disablePreview: true,
365353
},
366354
});
367-
}
355+
};
368356

369-
estimateMonthSize(index, cache) {
357+
estimateMonthSize = (index, cache) => {
370358
const { direction, minDate } = this.props;
371359
const { scrollArea } = this.state;
372360
if (cache) {
@@ -378,7 +366,7 @@ class Calendar extends PureComponent {
378366
const { start, end } = getMonthDisplayRange(monthStep, this.dateOptions);
379367
const isLongMonth = differenceInDays(end, start, this.dateOptions) + 1 > 7 * 5;
380368
return isLongMonth ? scrollArea.longMonthHeight : scrollArea.monthHeight;
381-
}
369+
};
382370
render() {
383371
const {
384372
showDateDisplay,

src/components/DateInput/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ class DateInput extends PureComponent {
77
constructor(props, context) {
88
super(props, context);
99

10-
this.onKeyDown = this.onKeyDown.bind(this);
11-
this.onChange = this.onChange.bind(this);
12-
this.onBlur = this.onBlur.bind(this);
13-
1410
this.state = {
1511
invalid: false,
1612
changed: false,
@@ -50,22 +46,22 @@ class DateInput extends PureComponent {
5046
}
5147
}
5248

53-
onKeyDown(e) {
49+
onKeyDown = e => {
5450
const { value } = this.state;
5551

5652
if (e.key === 'Enter') {
5753
this.update(value);
5854
}
59-
}
55+
};
6056

61-
onChange(e) {
57+
onChange = e => {
6258
this.setState({ value: e.target.value, changed: true, invalid: false });
63-
}
59+
};
6460

65-
onBlur() {
61+
onBlur = () => {
6662
const { value } = this.state;
6763
this.update(value);
68-
}
64+
};
6965

7066
render() {
7167
const { className, readOnly, placeholder, disabled, onFocus } = this.props;

src/components/DateRange/index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ import coreStyles from '../../styles';
1010
class DateRange extends Component {
1111
constructor(props, context) {
1212
super(props, context);
13-
this.setSelection = this.setSelection.bind(this);
14-
this.handleRangeFocusChange = this.handleRangeFocusChange.bind(this);
15-
this.updatePreview = this.updatePreview.bind(this);
16-
this.calcNewSelection = this.calcNewSelection.bind(this);
1713
this.state = {
1814
focusedRange: props.initialFocusedRange || [findNextRangeIndex(props.ranges), 0],
1915
preview: null,
2016
};
2117
this.styles = generateStyles([coreStyles, props.classNames]);
2218
}
23-
calcNewSelection(value, isSingleValue = true) {
19+
calcNewSelection = (value, isSingleValue = true) => {
2420
const focusedRange = this.props.focusedRange || this.state.focusedRange;
2521
const { ranges, onChange, maxDate, moveRangeOnFirstSelection, disabledDates } = this.props;
2622
const focusedRangeIndex = focusedRange[0];
@@ -75,8 +71,8 @@ class DateRange extends Component {
7571
range: { startDate, endDate },
7672
nextFocusRange: nextFocusRange,
7773
};
78-
}
79-
setSelection(value, isSingleValue) {
74+
};
75+
setSelection = (value, isSingleValue) => {
8076
const { onChange, ranges, onRangeFocusChange } = this.props;
8177
const focusedRange = this.props.focusedRange || this.state.focusedRange;
8278
const focusedRangeIndex = focusedRange[0];
@@ -94,12 +90,12 @@ class DateRange extends Component {
9490
preview: null,
9591
});
9692
onRangeFocusChange && onRangeFocusChange(newSelection.nextFocusRange);
97-
}
98-
handleRangeFocusChange(focusedRange) {
93+
};
94+
handleRangeFocusChange = focusedRange => {
9995
this.setState({ focusedRange });
10096
this.props.onRangeFocusChange && this.props.onRangeFocusChange(focusedRange);
101-
}
102-
updatePreview(val) {
97+
};
98+
updatePreview = val => {
10399
if (!val) {
104100
this.setState({ preview: null });
105101
return;
@@ -108,7 +104,7 @@ class DateRange extends Component {
108104
const focusedRange = this.props.focusedRange || this.state.focusedRange;
109105
const color = ranges[focusedRange[0]].color || rangeColors[focusedRange[0]] || color;
110106
this.setState({ preview: { ...val.range, color } });
111-
}
107+
};
112108
render() {
113109
return (
114110
<Calendar

src/components/DayCell/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@ class DayCell extends Component {
1212
hover: false,
1313
active: false,
1414
};
15-
this.getClassNames = this.getClassNames.bind(this);
16-
this.handleMouseEvent = this.handleMouseEvent.bind(this);
17-
this.handleKeyEvent = this.handleKeyEvent.bind(this);
18-
this.renderSelectionPlaceholders = this.renderSelectionPlaceholders.bind(this);
19-
this.renderPreviewPlaceholder = this.renderPreviewPlaceholder.bind(this);
2015
}
2116

22-
handleKeyEvent(event) {
17+
handleKeyEvent = event => {
2318
const { day, onMouseDown, onMouseUp } = this.props;
2419
if ([13 /* space */, 32 /* enter */].includes(event.keyCode)) {
2520
if (event.type === 'keydown') onMouseDown(day);
2621
else onMouseUp(day);
2722
}
28-
}
29-
handleMouseEvent(event) {
23+
};
24+
handleMouseEvent = event => {
3025
const { day, disabled, onPreviewChange, onMouseEnter, onMouseDown, onMouseUp } = this.props;
3126
const stateChanges = {};
3227
if (disabled) {
@@ -60,8 +55,8 @@ class DayCell extends Component {
6055
if (Object.keys(stateChanges).length) {
6156
this.setState(stateChanges);
6257
}
63-
}
64-
getClassNames() {
58+
};
59+
getClassNames = () => {
6560
const {
6661
isPassive,
6762
isToday,
@@ -86,8 +81,8 @@ class DayCell extends Component {
8681
[styles.dayHovered]: this.state.hover,
8782
[styles.dayActive]: this.state.active,
8883
});
89-
}
90-
renderPreviewPlaceholder() {
84+
};
85+
renderPreviewPlaceholder = () => {
9186
const { preview, day, styles } = this.props;
9287
if (!preview) return null;
9388
const startDate = preview.startDate ? endOfDay(preview.startDate) : null;
@@ -106,8 +101,8 @@ class DayCell extends Component {
106101
style={{ color: preview.color }}
107102
/>
108103
);
109-
}
110-
renderSelectionPlaceholders() {
104+
};
105+
renderSelectionPlaceholders = () => {
111106
const { styles, ranges, day } = this.props;
112107
if (this.props.displayMode === 'date') {
113108
let isSelected = isSameDay(this.props.day, this.props.date);
@@ -153,7 +148,7 @@ class DayCell extends Component {
153148
style={{ color: range.color || this.props.color }}
154149
/>
155150
));
156-
}
151+
};
157152
render() {
158153
const { styles } = this.props;
159154
return (
@@ -201,6 +196,7 @@ DayCell.propTypes = {
201196
preview: PropTypes.shape({
202197
startDate: PropTypes.object,
203198
endDate: PropTypes.object,
199+
color: PropTypes.string,
204200
}),
205201
onPreviewChange: PropTypes.func,
206202
previewColor: PropTypes.string,

src/components/DefinedRange/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ class DefinedRange extends Component {
1313
rangeOffset: 0,
1414
focusedInput: -1,
1515
};
16-
this.handleRangeChange = this.handleRangeChange.bind(this);
1716
}
1817

19-
handleRangeChange(range) {
18+
handleRangeChange = range => {
2019
const { onChange, ranges, focusedRange } = this.props;
2120
const selectedRange = ranges[focusedRange[0]];
2221
if (!onChange || !selectedRange) return;
2322
onChange({
2423
[selectedRange.key || `range${focusedRange[0] + 1}`]: { ...selectedRange, ...range },
2524
});
26-
}
25+
};
2726

2827
getRangeOptionValue(option) {
2928
const { ranges = [], focusedRange = [] } = this.props;

src/components/InputRangeField/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const MAX = 99999;
77
class InputRangeField extends Component {
88
constructor(props, context) {
99
super(props, context);
10-
11-
this.onChange = this.onChange.bind(this);
1210
}
1311

1412
shouldComponentUpdate(nextProps) {
@@ -21,14 +19,14 @@ class InputRangeField extends Component {
2119
);
2220
}
2321

24-
onChange(e) {
22+
onChange = e => {
2523
const { onChange } = this.props;
2624

2725
let value = parseInt(e.target.value, 10);
2826
value = isNaN(value) ? 0 : Math.max(Math.min(MAX, value), MIN);
2927

3028
onChange(value);
31-
}
29+
};
3230

3331
render() {
3432
const { label, placeholder, value, styles, onBlur, onFocus } = this.props;

0 commit comments

Comments
 (0)