Skip to content

Commit

Permalink
code optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang740 committed Aug 23, 2017
1 parent 47ed48f commit 030e087
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
11 changes: 5 additions & 6 deletions src/DatePicker.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default abstract class DatePicker extends React.PureComponent<PropsType,
}
}

computeVisible = (fullHeight: number, clientHeight: number, scrollTop: number) => {
computeVisible = (clientHeight: number, scrollTop: number) => {
let needUpdate = false;
const MAX_VIEW_PORT = clientHeight * 2;
const MIN_VIEW_PORT = clientHeight;
Expand Down Expand Up @@ -273,11 +273,10 @@ export default abstract class DatePicker extends React.PureComponent<PropsType,

createOnScroll = () => {
let timer: any;
let fullHeight = 0, clientHeight = 0, scrollTop = 0;
let clientHeight = 0, scrollTop = 0;

return (data: { full: number, client: number, top: number }) => {
const { full, client, top } = data;
fullHeight = full;
const { client, top } = data;
clientHeight = client;
scrollTop = top;

Expand All @@ -287,14 +286,14 @@ export default abstract class DatePicker extends React.PureComponent<PropsType,

timer = setTimeout(() => {
timer = undefined;
if (this.computeVisible(fullHeight, clientHeight, scrollTop)) {
if (this.computeVisible(clientHeight, scrollTop)) {
this.forceUpdate();
}
}, 64);
};
}

onCellClick = (day: Models.CellData, monthData: Models.MonthData) => {
onCellClick = (day: Models.CellData) => {
if (!day.tick) return;
this.props.onCellClick && this.props.onCellClick(new Date(day.tick));
}
Expand Down
4 changes: 2 additions & 2 deletions src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class DatePicker extends Component {

this.visibleMonth = this.visibleMonth.slice(0, this.props.initalMonths);

this.state.months.forEach((m, index) => {
this.state.months.forEach((m) => {
m.updateLayout && m.updateLayout();
});

Expand Down Expand Up @@ -88,7 +88,7 @@ export default class DatePicker extends Component {
}
<div className="months">
{
this.state.months.map((m, index) => {
this.state.months.map((m) => {
const hidden = m.height && this.visibleMonth.indexOf(m) < 0;
if (hidden) {
return <div key={m.title + '_shallow'} style={{ height: m.height }}></div>;
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/AnimateWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

interface PropsType {
export interface PropsType {
visible: boolean;
className?: string;
displayType?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/calendar/ShortcutPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

interface PropsType {
export interface PropsType {
locale: GlobalModels.Locale;
onSelect: (startDate?: Date, endDate?: Date) => void;
}
Expand Down

0 comments on commit 030e087

Please sign in to comment.