Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix react16 warning, ref https://github.com/ant-design/ant-design-mob… #28

Merged
merged 5 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ android/
xcuserdata
yarn.lock
.vscode
_ts2js
_ts2js
es
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"jest": {
"collectCoverageFrom": [
"src/*"
"lib/*"
Copy link
Member Author

@silentcloud silentcloud Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样改,覆盖率就不是源码了吧,是不是应该自定义 transform 才对 @paranoidjk

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是我现在 test 里面就是引用的 lib

你可以试试改成 test 里面 引用 src,并且加上对应的 jest transform

注意 import '../' 是会应用 lib 的

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先按你这样搞吧,后面有时间再换 src 好了

],
"transform": {
"\\.tsx?$": "./node_modules/rc-tools/scripts/jestPreprocessor.js",
Expand All @@ -50,6 +50,7 @@
"devDependencies": {
"coveralls": "^2.11.15",
"jest": "^20.0.0",
"@types/jest": "^19.2.4",
"@types/react": "~0.14.41",
"@types/react-dom": "~0.14.18",
"@types/react-native": "~0.29.36",
Expand All @@ -60,7 +61,7 @@
"react": "15.5.x",
"react-dom": "15.5.x",
"react-native": "0.41.x",
"react-native-index-page": "~0.1.0"
"react-native-index-page": "~0.2.0"
},
"typings": "./lib/index.d.ts",
"pre-commit": [
Expand Down
93 changes: 47 additions & 46 deletions src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,33 @@ const TIME = 'time';
const MONTH = 'month';
const YEAR = 'year';

const DatePicker = React.createClass<IDatePickerProps, any>({
getDefaultProps() {
return {
prefixCls: 'rmc-date-picker',
pickerPrefixCls: 'rmc-picker',
locale: defaultLocale,
mode: DATE,
minuteStep: 1,
onDateChange() {
},
};
},

getInitialState() {
return {
date: this.props.date || this.props.defaultDate,
};
},
class DatePicker extends React.Component<IDatePickerProps, any> {
static defaultProps = {
prefixCls: 'rmc-date-picker',
pickerPrefixCls: 'rmc-picker',
locale: defaultLocale,
mode: DATE,
minuteStep: 1,
onDateChange() {
},
};

state = {
date: this.props.date || this.props.defaultDate,
};

defaultMinDate: any;
defaultMaxDate: any;

componentWillReceiveProps(nextProps) {
if ('date' in nextProps) {
this.setState({
date: nextProps.date || nextProps.defaultDate,
});
}
},
}

onValueChange(values, index) {
onValueChange = (values, index) => {
const value = parseInt(values[index], 10);
const props = this.props;
const { mode } = props;
Expand Down Expand Up @@ -92,78 +91,80 @@ const DatePicker = React.createClass<IDatePickerProps, any>({
date: newValue,
});
}
props.onDateChange(newValue);
},
if (props.onDateChange) {
props.onDateChange(newValue);
}
}

getDefaultMinDate() {
if (!this.defaultMinDate) {
this.defaultMinDate = this.getGregorianCalendar([2000, 1, 1, 0, 0, 0]);
}
return this.defaultMinDate;
},
}

getDefaultMaxDate() {
if (!this.defaultMaxDate) {
this.defaultMaxDate = this.getGregorianCalendar([2030, 1, 1, 23, 59, 59]);
}
return this.defaultMaxDate;
},
}

getDate() {
return this.state.date || this.getDefaultMinDate();
},
}

getValue() {
return this.getDate();
},
}

getMinYear() {
return this.getMinDate().year();
},
}

getMaxYear() {
return this.getMaxDate().year();
},
}

getMinMonth() {
return this.getMinDate().month();
},
}

getMaxMonth() {
return this.getMaxDate().month();
},
}

getMinDay() {
return this.getMinDate().date();
},
}

getMaxDay() {
return this.getMaxDate().date();
},
}

getMinHour() {
return this.getMinDate().hour();
},
}

getMaxHour() {
return this.getMaxDate().hour();
},
}

getMinMinute() {
return this.getMinDate().minute();
},
}

getMaxMinute() {
return this.getMaxDate().minute();
},
}

getMinDate() {
return this.props.minDate || this.getDefaultMinDate();
},
}

getMaxDate() {
return this.props.maxDate || this.getDefaultMaxDate();
},
}

getDateData() {
const { locale, formatMonth, formatDay, mode } = this.props;
Expand Down Expand Up @@ -231,7 +232,7 @@ const DatePicker = React.createClass<IDatePickerProps, any>({
monthCol,
{ key: 'day', props: { children: days } },
];
},
}

getTimeData() {
let minHour = 0;
Expand Down Expand Up @@ -287,7 +288,7 @@ const DatePicker = React.createClass<IDatePickerProps, any>({
}

const minutes: any[] = [];
for (let i = minMinute; i <= maxMinute; i += minuteStep) {
for (let i = minMinute; i <= maxMinute; i += minuteStep!) {
minutes.push({
value: i + '',
label: locale.minute ? i + locale.minute + '' : pad(i),
Expand All @@ -297,11 +298,11 @@ const DatePicker = React.createClass<IDatePickerProps, any>({
{ key: 'hours', props: { children: hours } },
{ key: 'minutes', props: { children: minutes } },
];
},
}

getGregorianCalendar(arg) {
return moment(arg);
},
}

clipDate(date) {
const { mode } = this.props;
Expand Down Expand Up @@ -336,7 +337,7 @@ const DatePicker = React.createClass<IDatePickerProps, any>({
}
}
return date;
},
}

getValueCols() {
const { mode } = this.props;
Expand Down Expand Up @@ -371,7 +372,7 @@ const DatePicker = React.createClass<IDatePickerProps, any>({
value,
cols,
};
},
}

render() {
const { value, cols } = this.getValueCols();
Expand All @@ -389,7 +390,7 @@ const DatePicker = React.createClass<IDatePickerProps, any>({
{cols}
</MultiPicker>
);
},
});
}
}

export default DatePicker;
21 changes: 10 additions & 11 deletions src/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ export interface IPopupDatePickerProps extends IPopupPickerProps {
onChange?: (date?) => void;
date?: any;
}
const PopupDatePicker = React.createClass<IPopupDatePickerProps, any>({
getDefaultProps() {
return {
pickerValueProp: 'date',
pickerValueChangeProp: 'onDateChange',
} as any;
},

onOk(v) {
class PopupDatePicker extends React.Component<IPopupDatePickerProps, any> {
static defaultProps = {
pickerValueProp: 'date',
pickerValueChangeProp: 'onDateChange',
};

onOk = (v) => {
const { onChange, onOk } = this.props;
if (onChange) {
onChange(v);
}
if (onOk) {
onOk(v);
}
},
}

render() {
return (<PopupPicker
Expand All @@ -33,7 +32,7 @@ const PopupDatePicker = React.createClass<IPopupDatePickerProps, any>({
{...this.props}
onOk={this.onOk}
/>);
},
});
}
}

export default PopupDatePicker;
79 changes: 0 additions & 79 deletions tests/simple.spec.tsx

This file was deleted.