Skip to content

Commit 95d63f8

Browse files
refactor-botWscats
authored andcommitted
refactor: clean up React tutorial project
- Remove ~12 console.log across multiple components - Remove commented-out code (imports, router guards, reducer logic) - Fix const→let bug in errorHandler (string concatenation on const) - Replace Chinese comments with English - Replace var with const for imports - Add JSDoc comments
1 parent e67a6de commit 95d63f8

File tree

10 files changed

+19
-57
lines changed

10 files changed

+19
-57
lines changed

react+webpack+react-router/app/components/index/skill.jsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
//var React = require('react');
21
import React from 'react';
32
import PropTypes from 'prop-types';
4-
//新版本的写法 推荐
3+
54
class Skill extends React.Component {
65
constructor(props) {
76
super(props);
8-
// 设置 initial state
7+
// Set initial state
98
this.state = {
109
text: props.initialValue || 'Hello Wscats'
1110
};
12-
// ES6 类中函数必须手动绑定
11+
// Bind handler in ES6 class
1312
this.handleChange = this.handleChange.bind(this);
1413
}
1514
componentDidMount() {
16-
console.log(this.props.match)
1715
}
1816
handleChange(event) {
19-
console.log(this)
2017
this.setState({
2118
text: event.target.value
2219
});
@@ -35,11 +32,11 @@ class Skill extends React.Component {
3532
}
3633
}
3734
Skill.propTypes = {
38-
//定义传入props中的属性各种类型
39-
initialValue: PropTypes.string.isRequired//PropTypes.string
35+
// Define prop types for validation
36+
initialValue: PropTypes.string.isRequired
4037
};
4138
Skill.defaultProps = {
42-
//组件默认的props对象
39+
// Default props
4340
initialValue: 'Hello Oaoafly'
4441
};
4542
module.exports = Skill;

react+webpack/app/components/root.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
//var React = require('react');
21
import React, { Component } from 'react';
32
import {
43
BrowserRouter as Router,
54
Route,
65
Link
76
} from 'react-router-dom';
87
import { matchRoutes, renderRoutes } from 'react-router-config';
9-
//新版本的写法 推荐
10-
//class Wscats extends React.Component {
8+
9+
/** Root component: renders top-level navigation and child routes. */
1110
class Wscats extends Component {
1211
render() {
1312
return(
@@ -16,7 +15,6 @@ class Wscats extends Component {
1615
<Link to="/">home</Link> <Link to="/index">index</Link>
1716
{/* child routes won't render without this */}
1817
{renderRoutes(this.props.route.routes)}
19-
{console.log(this)}
2018
</div>
2119
)
2220
}

react+webpack/app/components/wscats.jsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
//var React = require('react');
21
import React, { Component } from 'react';
3-
var routes = require("../routes.js");
2+
const routes = require("../routes.js");
43
import {
54
BrowserRouter as Router,
65
Route,
76
Link
87
} from 'react-router-dom';
98
import { matchRoutes, renderRoutes } from 'react-router-config';
109

11-
var IndexA = require('./index/indexA.jsx');
12-
var IndexB = require('./index/indexB.jsx');
13-
console.log(routes)
14-
//新版本的写法 推荐
15-
//class Wscats extends React.Component {
10+
const IndexA = require('./index/indexA.jsx');
11+
const IndexB = require('./index/indexB.jsx');
12+
13+
/** Wscats component: renders child routes with navigation links. */
1614
class Wscats extends Component {
1715
render() {
1816
return(
1917
<div>
2018
<div>Wscats</div>
2119
<Link to="/index/childA">childA</Link> <Link to="/index/childB">childB</Link>
2220
{renderRoutes(this.props.route.routes)}
23-
{console.log(this.props.route.routes)}
24-
{console.log(routes)}
2521
</div>
2622
)
2723
}

react+webpack/app/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
const React = require('react');
22
const ReactDom = require('react-dom');
3-
//npm install --save react-router-config
43
import { matchRoutes, renderRoutes } from 'react-router-config'
54
import {
65
BrowserRouter as Router,
76
Route,
87
Link
98
} from 'react-router-dom'
109

11-
1210
const routes = require("./routes.js");
1311
matchRoutes(routes, '/index');
14-
console.log(routes)
15-
//默认路由
12+
// Default route
1613
const branch = matchRoutes(routes, '/index')
1714
ReactDom.render((
1815
<Router>

react/reactERP/src/components/login/login.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import './login.scss'
44

55
class LoginComponent extends Component{
66
login(){
7-
console.log(this)
87
this.props.router.push({pathname: '/home/cnode'})
98
}
109
render(){

react/reactERP/src/modules/login/LoginReducer.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
// import httpclient from '../../utils/HttpClient'
21
import * as LoginConstants from './LoginConstants';
32
import { combineReducers } from 'redux';
43
import update from 'react-addons-update'
5-
function login(state = [], action){
6-
7-
// httpclient.post(action.url, action.data).then(response => {
8-
// console.log(response);
9-
// state.state = response.state;
10-
// return state;
11-
// })
124

13-
// return state;
14-
15-
// state.dataset = action.response.data.data;
16-
// console.log(action);
5+
function login(state = [], action){
176
const newData = update(state, {$push: [action.body]});
18-
// console.log(newData, state);
197
return newData;
208
}
219

react/reactERP/src/utils/HttpClient.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@ function getUrl(path) {
1313
}
1414

1515
const errorHandler = (err) => {
16-
const str = err.response.status
16+
let str = err.response.status
1717
str += ' - '
1818
str += err.response.statusText
19-
str += '<br/>请求路径:<br/>'
19+
str += '<br/>Request path:<br/>'
2020
str += err.response.error.url
21-
console.log(str);
2221
}
2322

2423
const HttpClient = {
2524
get: (path, query) => new Promise((resolve, reject) => {
26-
// if(!window.localStorage.getItem('access_token')){
27-
// router.push({name: 'login'});
28-
// return false;
29-
// }
3025
const req = request
3126
.get(getUrl(path))
3227
.query(query)
@@ -42,10 +37,6 @@ const HttpClient = {
4237
}),
4338

4439
post: (path, formdata, query) => new Promise((resolve, reject) => {
45-
// if(path.indexOf('login/index') < 0 && !window.localStorage.getItem('access_token')){
46-
// router.push({name: 'login'});
47-
// return false;
48-
// }
4940
request
5041
.post(getUrl(path))
5142
.set('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')

react/redux/middleware/src/utils/HttpClient.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ function getUrl(path) {
1313
}
1414

1515
const errorHandler = (err) => {
16-
const str = err.response.status
16+
let str = err.response.status
1717
str += ' - '
1818
str += err.response.statusText
19-
str += '<br/>请求路径:<br/>'
19+
str += '<br/>Request path:<br/>'
2020
str += err.response.error.url
21-
console.log(str);
2221
}
2322

2423
const HttpClient = {

组件/1.weui/components/xpanel.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ let Xpanel = React.createClass({
1212
let self = this;
1313
xmlhttp.onreadystatechange = function() {
1414
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
15-
console.log(JSON.parse(xmlhttp.responseText));
1615
setTimeout(() => {
1716
self.setState({
1817
news: JSON.parse(xmlhttp.responseText)
@@ -32,7 +31,6 @@ let Xpanel = React.createClass({
3231
let html;
3332
if (self.state.news) {
3433
html = self.state.news.newslist.map((item) => {
35-
console.log(item);
3634
return (
3735
<a key={item.id} href="javascript:void(0);" className="weui-media-box weui-media-box_appmsg">
3836
<div className="weui-media-box__hd">

组件/1.weui/components/xsearch.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ let Xsearch = React.createClass({
44
},
55
focusing() {
66
this.setState({bool: true})
7-
console.log(this.refs.input)
87
this.refs.input.focus()
98
},
109
cancelFocusing() {

0 commit comments

Comments
 (0)