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

Commit abe7f79

Browse files
committed
Use shallow-equal instead of JSON stringify
1 parent ea8c9a9 commit abe7f79

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
],
3939
"dependencies": {
4040
"classnames": "^2.2.6",
41-
"normalize.css": "^8.0.1",
4241
"prop-types": "^15.7.2",
43-
"react-list": "^0.8.13"
42+
"react-list": "^0.8.13",
43+
"shallow-equal": "^1.2.1"
4444
},
4545
"peerDependencies": {
46-
"react": "^0.14 || ^15.0.0-rc || >=15.0",
47-
"date-fns": "2.0.0-alpha.7 || >=2.0.0"
46+
"date-fns": "2.0.0-alpha.7 || >=2.0.0",
47+
"react": "^0.14 || ^15.0.0-rc || >=15.0"
4848
},
4949
"devDependencies": {
5050
"@babel/cli": "^7.7.7",
@@ -57,6 +57,7 @@
5757
"babel-eslint": "^10.0.3",
5858
"babel-loader": "^8.0.6",
5959
"css-loader": "^3.2.0",
60+
"date-fns": "^2.8.1",
6061
"enzyme": "^3.11.0",
6162
"enzyme-adapter-react-16": "^1.15.2",
6263
"enzyme-to-json": "^3.4.3",
@@ -67,18 +68,18 @@
6768
"eslint-plugin-prettier": "^3.1.2",
6869
"eslint-plugin-react": "^7.17.0",
6970
"jest": "^24.9.0",
71+
"normalize.css": "^8.0.1",
7072
"postcss": "^7.0.25",
7173
"postcss-cli": "^6.1.3",
7274
"postcss-import": "^12.0.1",
7375
"postcss-loader": "^3.0.0",
7476
"precss": "^4.0.0",
7577
"prettier": "^1.19.1",
78+
"react": "^16.12.0",
79+
"react-dom": "^16.12.0",
7680
"react-styleguidist": "^10.4.0",
7781
"style-loader": "^1.0.0",
7882
"url-loader": "^3.0.0",
79-
"webpack": "^4.41.5",
80-
"date-fns": "^2.8.1",
81-
"react": "^16.12.0",
82-
"react-dom": "^16.12.0"
83+
"webpack": "^4.41.5"
8384
}
8485
}

src/components/Calendar/index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import DateInput from '../DateInput';
66
import { calcFocusDate, generateStyles, getMonthDisplayRange } from '../../utils';
77
import classnames from 'classnames';
88
import ReactList from 'react-list';
9+
import { shallowEqualObjects } from 'shallow-equal';
910
import {
1011
addMonths,
1112
format,
@@ -32,8 +33,7 @@ class Calendar extends PureComponent {
3233
constructor(props, context) {
3334
super(props, context);
3435
this.dateOptions = { locale: props.locale };
35-
if (this.props.weekStartsOn !== undefined)
36-
this.dateOptions.weekStartsOn = this.props.weekStartsOn;
36+
if (props.weekStartsOn !== undefined) this.dateOptions.weekStartsOn = props.weekStartsOn;
3737
this.styles = generateStyles([coreStyles, props.classNames]);
3838
this.listSizeCache = {};
3939
this.isFirstRender = true;
@@ -133,7 +133,7 @@ class Calendar extends PureComponent {
133133
});
134134
}
135135

136-
if (JSON.stringify(prevProps.scroll) !== JSON.stringify(this.props.scroll)) {
136+
if (!shallowEqualObjects(prevProps.scroll, this.props.scroll)) {
137137
this.setState({ scrollArea: this.calcScrollArea(this.props) });
138138
}
139139
}
@@ -378,24 +378,27 @@ class Calendar extends PureComponent {
378378
minDate,
379379
rangeColors,
380380
color,
381+
navigatorRenderer,
382+
className,
383+
preview,
381384
} = this.props;
382385
const { scrollArea, focusedDate } = this.state;
383386
const isVertical = direction === 'vertical';
384-
const navigatorRenderer = this.props.navigatorRenderer || this.renderMonthAndYear;
387+
const monthAndYearRenderer = navigatorRenderer || this.renderMonthAndYear;
385388

386389
const ranges = this.props.ranges.map((range, i) => ({
387390
...range,
388391
color: range.color || rangeColors[i] || color,
389392
}));
390393
return (
391394
<div
392-
className={classnames(this.styles.calendarWrapper, this.props.className)}
395+
className={classnames(this.styles.calendarWrapper, className)}
393396
onMouseUp={() => this.setState({ drag: { status: false, range: {} } })}
394397
onMouseLeave={() => {
395398
this.setState({ drag: { status: false, range: {} } });
396399
}}>
397400
{showDateDisplay && this.renderDateDisplay()}
398-
{navigatorRenderer(focusedDate, this.changeShownDate, this.props)}
401+
{monthAndYearRenderer(focusedDate, this.changeShownDate, this.props)}
399402
{scroll.enabled ? (
400403
<div>
401404
{isVertical && this.renderWeekdays(this.dateOptions)}
@@ -426,8 +429,8 @@ class Calendar extends PureComponent {
426429
return (
427430
<Month
428431
{...this.props}
429-
onPreviewChange={this.props.onPreviewChange || this.updatePreview}
430-
preview={this.props.preview || this.state.preview}
432+
onPreviewChange={onPreviewChange || this.updatePreview}
433+
preview={preview || this.state.preview}
431434
ranges={ranges}
432435
key={key}
433436
drag={this.state.drag}
@@ -463,8 +466,8 @@ class Calendar extends PureComponent {
463466
return (
464467
<Month
465468
{...this.props}
466-
onPreviewChange={this.props.onPreviewChange || this.updatePreview}
467-
preview={this.props.preview || this.state.preview}
469+
onPreviewChange={onPreviewChange || this.updatePreview}
470+
preview={preview || this.state.preview}
468471
ranges={ranges}
469472
key={i}
470473
drag={this.state.drag}

0 commit comments

Comments
 (0)