Skip to content

Commit 4366cdf

Browse files
committed
完成reducer文档
1 parent b5ba590 commit 4366cdf

3 files changed

Lines changed: 56 additions & 29 deletions

File tree

README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# React Native旅程
1+
# React Native 学习旅程
22
###本文档前置条件
33
1. 已安装JDK,并配好环境变量。
44
2. 已安装如下Android SDK,并配好环境变量。
@@ -21,10 +21,8 @@
2121
### 安装Node.js
2222
- 从官网下载[Node.js 4.4.x](https://nodejs.org/dist/v4.4.2/node-v4.4.2-x64.msi)的官方4.x版本,``` 不要安装5.x版本 ```,安装时确保``` Add to PATH ```已选中状态。
2323
- 建议设置npm镜像以加速后面的过程(或使用科学上网工具)。
24-
<pre><code>
25-
npm config set registry https://registry.npm.taobao.org
26-
npm config set disturl https://npm.taobao.org/dist
27-
</code></pre>
24+
<pre><code>npm config set registry https://registry.npm.taobao.org
25+
npm config set disturl https://npm.taobao.org/dist</code></pre>
2826

2927
### 安装Gradle
3028
- 虽然在编译Android项目时会自动下载,但如果网络状态不好,很容易下载失败,建议先下载[gradle-2.4-all.zip](http://pan.baidu.com/s/1c0dcgfe)
@@ -54,22 +52,16 @@ npm config set disturl https://npm.taobao.org/dist
5452
<pre><code>adb reverse tcp:8081 tcp:8081</code></pre>
5553

5654
建议使用Android 5.0系统手机,不用手动设置Debug server host,但是最低要求Android 4.1系统手机。
57-
提示:如果你执行``` adb devices ```没有问题,但执行上面``` adb reverse ```命令出问题,请下载[utility/adb.zip](https://raw.githubusercontent.com/Kennytian/learning-react-native/master/utility/adb.zip),解压后,将3个文件放在``` %ANDROID_HOME%\platform-tools ```
55+
56+
提示:如果你执行``` adb devices ```没有问题,但执行上面``` adb reverse ```命令出问题,请下载 [utility/adb.zip](https://raw.githubusercontent.com/Kennytian/learning-react-native/master/utility/adb.zip) ,解压后,将3个文件放在``` %ANDROID_HOME%\platform-tools ```
5857

5958
### 开发
6059
用IDE打开RNProject目录, 开始开发吧!
6160

6261
### 反馈
6362
- QQ:2225226
6463

65-
下一篇:[Redux之Action](https://raw.githubusercontent.com/Kennytian/learning-react-native/master/redux/actions.md)
66-
67-
68-
69-
70-
71-
72-
73-
74-
75-
64+
### 相关文档
65+
* [React Native 学习旅程](https://github.com/Kennytian/learning-react-native/blob/master/README.md)
66+
* [Redux 之 Action](https://github.com/Kennytian/learning-react-native/blob/master/redux/action.md)
67+
* [Redux 之 Reducer](https://github.com/Kennytian/learning-react-native/blob/master/redux/reducer.md)

redux/actions.md renamed to redux/action.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,7 @@ store里能直接通过`store.dispatch()`调用`dispatch()`方法,但多数情
3131

3232
`bindActionCreators()`更是可以自动把多个**action创建函数**绑定到`dispatch()`方法上。
3333

34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
45-
34+
### 相关文档
35+
* [React Native 学习旅程](https://github.com/Kennytian/learning-react-native/blob/master/README.md)
36+
* [Redux 之 Action](https://github.com/Kennytian/learning-react-native/blob/master/redux/action.md)
37+
* [Redux 之 Reducer](https://github.com/Kennytian/learning-react-native/blob/master/redux/reducer.md)

redux/reducer.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Reducer 技术要点
2+
3+
Action只描述了**有事情发生了**这一事实,而reducer要做的事就是如何更新state。
4+
5+
## 设计 State 结构
6+
在Redux应用中,所有的state都被保存在一个单一对象树中,建议设计一个良好的数据组织结构。如何才能以最简的形式把应用的state用对象描述出来?
7+
8+
以酒店应用为例,需要保存两个不同的内容:
9+
* 当前筛选后酒店列表的过滤条件
10+
* 默认酒店列表
11+
12+
通常,这个state树还需要存放其它一些UI数据,但尽量把这些数据与UI相关的state分开。
13+
14+
<pre><code>{
15+
visibilityFilter: 'SHOW_ALL',
16+
hotels:[
17+
{
18+
text: '公寓',
19+
isShow: true,
20+
},
21+
{
22+
text: '客栈',
23+
isShow: false
24+
}]
25+
}</code></pre>
26+
27+
> ### 处理 Reducer 关系时的注意事项
28+
> 开发复杂的应用时,不可避免会有一些数据相互引用。建议你尽可能地把 state 范式化,不存在嵌套。
29+
> 把有数据放到一个对象里,每个数据以 ID 为主键,不同数据相互引用时通过 ID 来查找。
30+
> 把应用的 state 想像成数据库。
31+
> 例如,实际开发中,在 state 里同时存放 `hotelsById: { id -> hotel } 和 hotels: array<id>` 是比较好的方式。
32+
33+
34+
35+
### 相关文档
36+
* [React Native 学习旅程](https://github.com/Kennytian/learning-react-native/blob/master/README.md)
37+
* [Redux 之 Action](https://github.com/Kennytian/learning-react-native/blob/master/redux/action.md)
38+
* [Redux 之 Reducer](https://github.com/Kennytian/learning-react-native/blob/master/redux/reducer.md)
39+
40+
41+
42+
43+

0 commit comments

Comments
 (0)