Skip to content

Commit f155019

Browse files
committed
update from master
1 parent c8c286c commit f155019

File tree

23 files changed

+76
-80
lines changed

23 files changed

+76
-80
lines changed

Ch02/webpack-dev-enviroment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
filename: 'index_bundle.js',
108108
},
109109
module: {
110-
// loaders 则是放欲使用的 loaders,在这边是使用 babel-loader 将所有 .js(这边用到正则式)相关档案(排除了 npm 安装的套件位置 node_modules)转译成浏览器可以阅读的 JavaScript。preset 则是使用的 babel 转译规则,这边使用 react、es2015
110+
// loaders 则是放欲使用的 loaders,在这边是使用 babel-loader 将所有 .js(这边用到正则式)相关档案(排除了 npm 安装的套件位置 node_modules)转译成浏览器可以阅读的 JavaScript。preset 则是使用的 babel 转译规则,这边使用 react、es2015。若是已经单独使用 .babelrc 作为 presets 设定的话,则可以省略 query
111111
loaders: [
112112
{
113113
test: /\.js$/,

Ch03/todo-examples/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"example": "examples"
88
},
99
"scripts": {
10-
"test": "echo \"Error: no test specified\" && exit 1",
11-
"dev": "webpack-dev-server --devtool eval --progress --colors --content-base build"
10+
"start": "webpack-dev-server --colors --inline --content-base ."
1211
},
1312
"author": "kdchang",
1413
"license": "MIT",

Ch03/todo-examples/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ module.exports = {
2020
test: /\.js$/,
2121
exclude: /node_modules/,
2222
loader: 'babel-loader',
23-
query: {
24-
presets: ['es2015', 'react'],
25-
},
2623
},
2724
],
2825
},

Ch04/props-state-introduction.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ app.js,使用 ES6 Class Component 写法:
3030

3131
```javascript
3232
class HelloMessage extends React.Component {
33+
// 若是需要绑定 this.方法或是需要在 constructor 使用 props,定义 state,就需要 constructor。若是在其他方法(如 render)使用 this.props 则不用一定要定义 constructor
3334
constructor(props) {
3435
// 对于 OOP 物件导向程式设计熟悉的读者应该对于 constructor 建构子的使用不陌生,事实上它是 ES6 的语法糖,骨子里还是 portotype based 物件导向程式语言。透过 extends 可以继承 React.Component 父类别。super 方法可以呼叫继承父类别的建构子
3536
super(props);
3637
this.state = {}
3738
}
39+
// render 是唯一必须的方法,但如果是单纯 render UI 建议使用 Functional Component 写法,效能较佳且较简洁
3840
render() {
3941
return (
4042
<div>Hello {this.props.name}</div>
@@ -55,6 +57,8 @@ HelloMessage.defaultProps = {
5557
ReactDOM.render(<HelloMessage name="Mark" />, document.getElementById('app'));
5658
```
5759

60+
关于 React ES6 class constructor super() 解释可以参考 [React ES6 class constructor super()](http://cheng.logdown.com/posts/2016/03/26/683329)
61+
5862
使用 Functional Component 写法:
5963

6064
```javascript
@@ -138,6 +142,8 @@ class Timer extends React.Component {
138142
ReactDOM.render(<Timer />, document.getElementById('app'));
139143
```
140144

145+
关于 Javascript this 用法可以参考 [Javascript:this用法整理](https://software.intel.com/zh-cn/blogs/2013/10/09/javascript-this)
146+
141147
## 事件处理(Event Handle)
142148
在前面的内容我们已经学会如何使用 props 和 state,接下来我们要更进一步学习在 React 内如何进行事件处理。下列将使用 React 官网的 An Application 当做例子,实作出一个简单的 TodoApp。
143149

@@ -283,6 +289,7 @@ ReactDOM.render(<MarkdownEditor />, document.getElementById('app'));
283289
## 延伸阅读
284290
1. [React 官方网站](https://facebook.github.io/react/index.html)
285291
2. [Top-Level API](https://facebook.github.io/react/docs/top-level-api.html)
292+
3. [Javascript:this用法整理](https://software.intel.com/zh-cn/blogs/2013/10/09/javascript-this)
286293

287294
## :door: 任意门
288295
| [回首页](../../../tree/zh-CN/) | [上一章:JSX 简明入门教学指南](../Ch03/react-jsx-introduction.md) | [下一章:React Component 规格与生命周期(Life Cycle)](../Ch04/react-component-life-cycle.md) |

Ch05/react-router-example/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ module.exports = {
2727
test: /\.js$/,
2828
exclude: /node_modules/,
2929
loader: 'babel-loader',
30-
query: {
31-
presets: ['es2015', 'react'],
32-
},
3330
}],
3431
},
3532
devServer: {

Ch06/react-immutable-introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ ImmutableJS 提供了 7 种不可修改的资料类型:`List`、`Map`、`Stack
203203
传统 JavaScript 比较方式,若资料型态为 Primitive 就不会有问题:
204204

205205
```javascript
206-
// 在 shouldComponentUpdate 比较接下来的 props 一否一致,若相同则不重新渲染,提升效能
206+
// 在 shouldComponentUpdate 比较接下来的 props 是否一致,若相同则不重新渲染,提升效能
207207
shouldComponentUpdate (nextProps) {
208208
return this.props.value !== nextProps.value;
209209
}
@@ -213,7 +213,7 @@ shouldComponentUpdate (nextProps) {
213213

214214
```javascript
215215
// 假设 this.props.value 为 { foo: 'app' }
216-
// 架设 nextProps.value 为 { foo: 'app' },
216+
// 假设 nextProps.value 为 { foo: 'app' },
217217
// 虽然两者值是一样,但由于 reference 位置不同,所以视为不同。但由于值一样应该要避免重复渲染
218218
this.props.value !== nextProps.value; // true
219219
```

Ch07/react-flux-example/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ module.exports = {
2727
test: /\.js$/,
2828
exclude: /node_modules/,
2929
loader: 'babel-loader',
30-
query: {
31-
presets: ['es2015', 'react'],
32-
},
3330
}],
3431
},
3532
devServer: {

Ch07/react-redux-example/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ module.exports = {
2727
test: /\.js$/,
2828
exclude: /node_modules/,
2929
loader: 'babel-loader',
30-
query: {
31-
presets: ['es2015', 'react'],
32-
},
3330
}],
3431
},
3532
devServer: {

Ch07/react-redux-introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ store.dispatch({ type: 'DECREMENT' });
9191

9292
1. createStore:`createStore(reducer, [preloadedState], [enhancer])`
9393

94-
我们知道在 Redux 中只会有一个 store。在产生 store 时我们会使用 `createStore` 这个 API 来创建 store。第一个参数放入我们的 `reducer` 或是有多个 `reducers` combine(使用 `combineReducers`)在一起的 `rootRuducers`。第二个参数我们会放入希望预先载入的 `state` 例如:user session 等。第三个参数通常会放入我们想要使用用来增强 Redux 功能的 `middlewares`,若有多个 `middlewares` 的话,通常会使用 `applyMiddleware` 来整合。
94+
我们知道在 Redux 中只会有一个 store。在产生 store 时我们会使用 `createStore` 这个 API 来创建 store。第一个参数放入我们的 `reducer` 或是有多个 `reducers` combine(使用 `combineReducers`)在一起的 `rootReducers`。第二个参数我们会放入希望预先载入的 `state` 例如:user session 等。第三个参数通常会放入我们想要使用用来增强 Redux 功能的 `middlewares`,若有多个 `middlewares` 的话,通常会使用 `applyMiddleware` 来整合。
9595

9696
2. Store
9797

@@ -102,7 +102,7 @@ store.dispatch({ type: 'DECREMENT' });
102102
- subscribe(listener)
103103
- replaceReducer(nextReducer)
104104

105-
关于 Store 重点是要知道 Redux 只有一个 Sotre 负责存放整个 App 的 State,而唯一能改变 State 的方法只有发送 action。
105+
关于 Store 重点是要知道 Redux 只有一个 Store 负责存放整个 App 的 State,而唯一能改变 State 的方法只有发送 action。
106106

107107
3. combineReducers:`combineReducers(reducers)`
108108

Ch09/react-router-redux-github-finder/.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"extends": "airbnb",
33
"rules": {
44
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
5+
"import/no-extraneous-dependencies": [0],
6+
"linebreak-style": ["error", "unix"],
7+
"react/prop-types": ["error", {"ignore": ["children", "route"]}],
8+
"new-cap": [0],
59
},
610
"env" :{
711
"browser": true,

0 commit comments

Comments
 (0)