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

Commit 2190992

Browse files
committed
eslint 100%
1 parent dc8d001 commit 2190992

File tree

22 files changed

+226
-252
lines changed

22 files changed

+226
-252
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"react/jsx-no-literals": 0, //防止使用未包装的JSX字符串
8282
"react/jsx-no-undef": 1, //在JSX中禁止未声明的变量
8383
"react/jsx-pascal-case": 0, //为用户定义的JSX组件强制使用PascalCase
84-
"react/jsx-sort-props": 1, //强化props按字母排序
84+
"react/jsx-sort-props": 2, //强化props按字母排序
8585
"react/jsx-uses-react": 1, //防止反应被错误地标记为未使用
8686
"react/jsx-uses-vars": 2, //防止在JSX中使用的变量被错误地标记为未使用
8787
"react/no-danger": 0, //防止使用危险的JSX属性

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"build-win": "set NODE_ENV=production&& webpack --progress --hide-modules --config webpack.config.js",
1111
"test": "jest"
1212
},
13+
"pre-commit": [
14+
"lint"
15+
],
1316
"repository": {
1417
"type": "git",
1518
"url": "https://github.com/hyy1115/react-latest-framework.git"
@@ -47,6 +50,7 @@
4750
"less": "^2.7.1",
4851
"less-loader": "^2.2.2",
4952
"postcss-loader": "^0.7.0",
53+
"pre-commit": "^1.2.2",
5054
"react-error-overlay": "^1.0.9",
5155
"react-test-renderer": "^15.4.2",
5256
"react-transition-group": "^1.1.1",
@@ -55,7 +59,7 @@
5559
"redux-thunk": "^2.2.0",
5660
"style-loader": "^0.13.2",
5761
"url-loader": "^0.5.6",
58-
"webpack": "^3.8.1",
62+
"webpack": "^3.10.0",
5963
"webpack-bundle-analyzer": "^2.9.1",
6064
"webpack-dev-server": "^2.9.4"
6165
},
@@ -70,8 +74,8 @@
7074
"preact": "^8.2.6",
7175
"preact-compat": "^3.17.0",
7276
"prop-types": "^15.6.0",
73-
"react": "^16.1.1",
74-
"react-dom": "^16.1.1",
77+
"react": "^16.2.0",
78+
"react-dom": "^16.2.0",
7579
"react-hot-loader": "^3.1.2",
7680
"react-redux": "^5.0.6",
7781
"react-router": "^4.2.0",

src/App.js

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { connect } from 'react-redux'
3-
import { bindActionCreators } from 'redux';
3+
import { bindActionCreators } from 'redux'
44
import { Route, Router } from 'react-router-dom'
55
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup'
66
import createHistory from 'history/createHashHistory'
@@ -16,43 +16,55 @@ import asyncComponent from './AsyncComponent'
1616

1717
import Home from 'containers/Home/Home'
1818
import ReactChildrenMap from './containers/Commons/ReactChildrenMap'
19-
const Search = asyncComponent(() => import(/* webpackChunkName: "search" */ "./containers/Search/Search"))
20-
const BookList = asyncComponent(() => import(/* webpackChunkName: "bookList" */ "./containers/BookList/BookList"))
19+
const Search = asyncComponent(() => import(/* webpackChunkName: "search" */ './containers/Search/Search'))
20+
const BookList = asyncComponent(() => import(/* webpackChunkName: "bookList" */ './containers/BookList/BookList'))
2121

22-
@connect (
22+
@connect(
2323
state => {return {...state.global}},
2424
dispatch => bindActionCreators(global, dispatch)
2525
)
2626
export default class App extends React.Component {
27-
2827
componentDidMount() {
2928
window.addEventListener('hashchange', () => {
30-
this.props.currentAnimate('normal')
29+
this.props.currentAnimate('normal')
3130
})
3231
}
33-
34-
render() {
35-
const { animateCls } = this.props
36-
return (
37-
<Router history={history}>
38-
<Route render={({ location }) => {
39-
return(
40-
<CSSTransitionGroup
41-
transitionName={animateCls}
42-
transitionEnter={true}
43-
transitionLeave={true}
44-
transitionEnterTimeout={400}
45-
transitionLeaveTimeout={400}
46-
>
47-
<ReactChildrenMap key={location.pathname}>
48-
<Route location={location} exact path="/" component={Home} />
49-
<Route location={location} path="/search" component={Search} />
50-
<Route location={location} path="/bookList/:bookId" component={BookList} />
51-
</ReactChildrenMap>
52-
</CSSTransitionGroup>
53-
)
54-
}}/>
55-
</Router>
56-
);
57-
}
32+
render() {
33+
const { animateCls } = this.props
34+
return (
35+
<Router history={history}>
36+
<Route render={({ location }) => {
37+
return(
38+
<CSSTransitionGroup
39+
transitionEnter
40+
transitionEnterTimeout={400}
41+
transitionLeave
42+
transitionLeaveTimeout={400}
43+
transitionName={animateCls}
44+
>
45+
<ReactChildrenMap key={location.pathname}>
46+
<Route
47+
component={Home}
48+
exact
49+
location={location}
50+
path="/"
51+
/>
52+
<Route
53+
component={Search}
54+
location={location}
55+
path="/search"
56+
/>
57+
<Route
58+
component={BookList}
59+
location={location}
60+
path="/bookList/:bookId"
61+
/>
62+
</ReactChildrenMap>
63+
</CSSTransitionGroup>
64+
)
65+
}}
66+
/>
67+
</Router>
68+
)
69+
}
5870
}

src/actions/home.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const receiveNav = (response) => ({
1010
})
1111

1212
//获取服务器的参数,并且返回一个异步的dispatch,dispatch的对象是自己定义的action
13-
export const getNav = () => async (dispatch, getState) => {
13+
export const getNav = () => async (dispatch) => {
1414
try {
15-
let response = await instance.get(`/book/navigation`)
15+
let response = await instance.get('/book/navigation')
1616
await dispatch(receiveNav(response.data))
1717
} catch (error) {
1818
console.log('error: ', error)
@@ -26,9 +26,9 @@ const receiveBook = (response) => ({
2626
bookDetails: response.data
2727
})
2828

29-
export const getBook = () => async (dispatch, getState) => {
29+
export const getBook = () => async (dispatch) => {
3030
try {
31-
let response = await instance.get(`/book/list`)
31+
let response = await instance.get('/book/list')
3232
await dispatch(receiveBook(response.data))
3333
return response
3434
} catch (error) {

src/containers/Commons/MyScroll.js

Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,44 @@
77
* 该组件的作用和臭名昭著的IScroll插件相同,但是这个组件比IScroll封装的更好用,我已经在移动端项目全部页面使用了该组件。
88
* 组件使用教程可以查看我写的一篇博客:https://segmentfault.com/a/1190000010042474
99
* */
10-
exports.__esModule = true;
11-
12-
var _react = require('react');
13-
14-
var _react2 = _interopRequireDefault(_react);
15-
16-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17-
18-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
19-
20-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called'); } return call && (typeof call === 'object' || typeof call === 'function') ? call : self; }
21-
22-
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
23-
24-
var JRoll = require('jroll');
25-
26-
var MyJRoll = function (_React$Component) {
27-
_inherits(MyJRoll, _React$Component);
28-
29-
function MyJRoll(props) {
30-
_classCallCheck(this, MyJRoll);
31-
32-
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
33-
34-
_this.jroll = null;
35-
return _this;
10+
import React from 'react'
11+
import JRoll from 'jroll'
12+
export default class MyJRoll extends React.Component {
13+
constructor(props) {
14+
super(props)
15+
this.jroll = null
3616
}
37-
38-
MyJRoll.prototype.componentDidMount = function componentDidMount() {
39-
var wrappers = this.props.ID || 'wrappers';
40-
this.jroll = new JRoll('#' + wrappers);
41-
this.jroll.refresh();
42-
};
43-
44-
MyJRoll.prototype.componentDidUpdate = function componentDidUpdate() {
45-
var _this2 = this;
46-
47-
setTimeout(function () {
48-
return _this2.jroll.refresh();
49-
}, 400);
50-
};
51-
52-
MyJRoll.prototype.render = function render() {
53-
var _props = this.props,
54-
height = _props.height,
55-
maxHeight = _props.maxHeight;
56-
57-
var _style = void 0;
17+
componentDidMount() {
18+
let wrappers = this.props.ID || 'wrappers'
19+
this.jroll = new JRoll(`#${wrappers}`)
20+
this.jroll.refresh()
21+
this.jroll.on('scrollEnd', () => {
22+
this.jroll.refresh()
23+
})
24+
}
25+
componentDidUpdate() {
26+
setTimeout(() => this.jroll.refresh(), 400)
27+
}
28+
render() {
29+
const { height, maxHeight, bgColor } = this.props
30+
let _style
5831
if (!maxHeight) {
59-
_style = { height: height ? height : '100%' };
32+
_style = {height: height ? height : '100%', background: bgColor ? bgColor : '#f6f6f6'}
6033
} else {
61-
_style = { maxHeight: maxHeight };
34+
_style = {maxHeight: maxHeight, background: bgColor ? bgColor : '#f6f6f6'}
6235
}
63-
return _react2.default.createElement(
64-
'div',
65-
{ id: this.props.ID ? this.props.ID : 'wrappers', style: _style },
66-
_react2.default.createElement(
67-
'ul',
68-
{ id: 'scroller', className: 'clearfix' },
69-
this.props.children
70-
)
71-
);
72-
};
73-
74-
return MyJRoll;
75-
}(_react2.default.Component);
76-
77-
exports.default = MyJRoll;
36+
return (
37+
<div
38+
id={this.props.ID ? this.props.ID : 'wrappers'}
39+
style={_style}
40+
>
41+
<ul
42+
className="clearfix"
43+
id="scroller"
44+
>
45+
{this.props.children}
46+
</ul>
47+
</div>
48+
)
49+
}
50+
}

src/containers/Commons/ReactChildrenMap.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import warning from 'fbjs/lib/warning'
1111
* <div>渲染内容</div>
1212
* </ReactChildrenMap>
1313
* */
14+
function warningFunc(children) {
15+
if (typeof children !== 'object') {
16+
warning(false, '你可能传入空元素,请传入react组件或者是DOM节点,children:%s')
17+
return false
18+
}
19+
return true
20+
}
1421
export default class ReactChildrenMap extends React.PureComponent {
1522
render() {
1623
if (warningFunc(this.props.children)) {
@@ -20,11 +27,4 @@ export default class ReactChildrenMap extends React.PureComponent {
2027
}
2128
ReactChildrenMap.propTypes = {
2229
children: PropTypes.array
23-
}
24-
function warningFunc(children) {
25-
if (typeof children !== 'object') {
26-
warning(false, '你可能传入空元素,请传入react组件或者是DOM节点,children:%s')
27-
return false
28-
}
29-
return true
3030
}

src/containers/Commons/SetDocumentTitle.js

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,23 @@
1717
}
1818
*
1919
* */
20-
exports.__esModule = true;
21-
22-
var _react = require('react');
23-
24-
var _react2 = _interopRequireDefault(_react);
25-
26-
var _propTypes = require('prop-types');
27-
28-
var _propTypes2 = _interopRequireDefault(_propTypes);
29-
30-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31-
32-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
33-
34-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called'); } return call && (typeof call === 'object' || typeof call === 'function') ? call : self; }
35-
36-
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
37-
38-
var SetDocumentTitle = function (_React$Component) {
39-
_inherits(SetDocumentTitle, _React$Component);
40-
41-
function SetDocumentTitle() {
42-
_classCallCheck(this, SetDocumentTitle);
43-
44-
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
20+
import React from 'react'
21+
import PropTypes from 'prop-types'
22+
export default class SetDocumentTitle extends React.PureComponent {
23+
componentDidMount() {
24+
this.setTitle()
4525
}
46-
47-
SetDocumentTitle.prototype.setTitle = function setTitle() {
48-
var title = this.props.title;
49-
50-
document.title = title;
51-
};
52-
53-
SetDocumentTitle.prototype.componentDidMount = function componentDidMount() {
54-
this.setTitle();
55-
};
56-
57-
SetDocumentTitle.prototype.componentDidUpdate = function componentDidUpdate() {
58-
this.setTitle();
59-
};
60-
61-
SetDocumentTitle.prototype.render = function render() {
62-
return _react2.default.Children.only(this.props.children);
63-
};
64-
65-
return SetDocumentTitle;
66-
}(_react2.default.Component);
67-
68-
exports.default = SetDocumentTitle;
69-
26+
componentDidUpdate() {
27+
this.setTitle()
28+
}
29+
setTitle() {
30+
const { title } = this.props
31+
document.title = title
32+
}
33+
render() {
34+
return React.Children.only(this.props.children)
35+
}
36+
}
7037
SetDocumentTitle.propTypes = {
71-
title: _propTypes2.default.string.isRequired
72-
};
38+
title: PropTypes.string
39+
}

src/containers/Commons/ShallowComponent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*eslint-disable*/
12
import React from 'react'
23
import isEqual from 'lodash/isEqual'
34
const ShallowComponent = (component) => {

0 commit comments

Comments
 (0)