Skip to content

Commit

Permalink
chore: update details
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui committed Aug 1, 2017
1 parent 0b43012 commit d6ec3ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Calendar = createReactClass({
};
},
componentWillReceiveProps(nextProps) {
if ('mode' in nextProps) {
if ('mode' in nextProps && this.state.mode !== nextProps.mode) {
this.setState({ mode: nextProps.mode });
}
},
Expand Down Expand Up @@ -213,13 +213,12 @@ const Calendar = createReactClass({
this.onPanelChange('date');
},
render() {
const props = this.props;
const { props, state } = this;
const {
locale, prefixCls, disabledDate,
dateInputPlaceholder, timePicker,
disabledTime,
} = props;
const state = this.state;
const { value, selectedValue, mode } = state;
const showTimePicker = mode === 'time';
const disabledTimeConfig = showTimePicker && disabledTime && timePicker ?
Expand Down
21 changes: 17 additions & 4 deletions src/RangeCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ function isEmptyArray(arr) {
return Array.isArray(arr) && (arr.length === 0 || arr.every(i => !i));
}

function isArraysEqual(a, b) {
if (a === b) return true;
if (a === null || typeof a === 'undefined' || b === null || typeof b === 'undefined') {
return false;
}
if (a.length !== b.length) return false;

for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}

function getValueFromSelectedValue(selectedValue) {
const [start, end] = selectedValue;
const newEnd = end && end.isSame(start, 'month') ? end.clone().add(1, 'month') : end;
Expand Down Expand Up @@ -112,6 +125,7 @@ const RangeCalendar = createReactClass({
},

componentWillReceiveProps(nextProps) {
const { state } = this;
const newState = {};
if ('value' in nextProps) {
if (nextProps.value) {
Expand All @@ -121,15 +135,15 @@ const RangeCalendar = createReactClass({
}
this.setState(newState);
}
if ('hoverValue' in nextProps) {
if ('hoverValue' in nextProps && !isArraysEqual(state.hoverValue, nextProps.hoverValue)) {
this.setState({ hoverValue: nextProps.hoverValue });
}
if ('selectedValue' in nextProps) {
newState.selectedValue = nextProps.selectedValue;
newState.prevSelectedValue = nextProps.selectedValue;
this.setState(newState);
}
if ('mode' in nextProps) {
if ('mode' in nextProps && !isArraysEqual(state.mode, nextProps.mode)) {
this.setState({ mode: nextProps.mode });
}
},
Expand Down Expand Up @@ -436,8 +450,7 @@ const RangeCalendar = createReactClass({
},

render() {
const props = this.props;
const state = this.state;
const { props, state } = this;
const {
prefixCls, dateInputPlaceholder,
timePicker, showOk, locale, showClear,
Expand Down

0 comments on commit d6ec3ce

Please sign in to comment.