Skip to content

Commit a6c0e67

Browse files
author
Wenjun Mao
authored
翻译
正好最近正在学redux, 看到还有文档没有翻译完全就简单的翻译了一下, 难免有疏漏和不准确, 求润色和修改~~~
1 parent 741ef42 commit a6c0e67

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

11_src/src/home.jsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
// Tutorial 12 - Provider-and-connect.js
1+
// 教程 12 - Provider-and-connect.js
22

3-
// Our tutorial is almost over and the only missing piece to leave you with a good overview of Redux is:
4-
// How do we read from our store's state and how do we dispatch actions?
3+
// 到这为止我们的教程就基本上结束了, 关于Redux唯一剩下的问题
4+
// 就是我们如何能读取store里面的state以及如何进行action的分发。
55

6-
// Both of these questions can be answered using a single react-redux's binding: connect.
6+
// 这两个问题都能够使用connect去解决。
77

8-
// As we previously explained, when using the Provider component we allow all components of our app to
9-
// access Redux. But this access can only be made through the undocumented feature "React's context". To
10-
// avoid asking you to use such a "dark" React API, React-Redux is exposing a function that you can use
11-
// on a component class.
8+
// 正如我们前面所讲解的, 当我们使用Provider组件时, 我们允许我们应用中的所有组件访问Redux.
9+
// 但是这种访问只能使用不正式的特性React's context来实现,
10+
// 为了避免这种"黑科技"式 (不规范) 的API调用,
11+
// React-Redux为我们暴露了一个组件中的函数让我们可以使用。
1212

13-
// The function we're talking about is "connect" and it allows to literally connect your component with your Redux's store.
14-
// By doing so, it provides your store's dispatch function through a component's prop and also adds any
15-
// properties you want to expose as part of your store's state.
13+
// 这个函数就是Connect, 它让我们可以实现一个组件和Redux store的绑定,
14+
// 通过这种绑定可以让store通过组件的属性(prop)分发函数,
15+
// 也可以根据我们自己的需要增加任何需要暴露的属性作为store里面state的一部分。
1616

17-
// Using "connect", you'll turn a dumb component into a smart component with very little code overhead
17+
// 使用了Connect, 你可以通过添加很少的代码让一个组件变得更"聪明",
1818
// (https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0).
1919

2020
// "connect" is a function that takes as parameters few mapping functions and that returns a function expecting
@@ -104,8 +104,7 @@ class Home extends React.Component {
104104
}
105105
}
106106

107-
// This is our select function that will extract from the state the data slice we want to expose
108-
// through props to our component.
107+
// 这是我们的select函数, 它会把我们需要在属性(prop)中对我们的组件暴露的数据从state中抽离出来
109108
const mapStateToProps = (state/*, props*/) => {
110109
return {
111110
frozen: state._time.frozen,
@@ -148,22 +147,22 @@ export default ConnectedHome
148147
export default somedecorator(MyClass)
149148
*/
150149

151-
// You can write:
150+
// 你可以这么写:
152151

153152
/*
154153
@somedecorator
155154
export default class MyClass {}
156155
*/
157156

158-
// Applying this syntax to redux connect, you can replace:
157+
// 通过这种特性使用redux connect, 我们可以把如下代码:
159158

160159
/*
161160
let mapStateToProps = (state) => { ... }
162161
class MyClass {}
163162
export default connect(mapStateToProps)(MyClass)
164163
*/
165164

166-
// by:
165+
// 替换成:
167166

168167
/*
169168
let mapStateToProps = (state) => { ... }

0 commit comments

Comments
 (0)