-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter: 使用 Redux 实现无限 ListView #6388
Flutter: 使用 Redux 实现无限 ListView #6388
Conversation
校对认领 @Glowin |
@TsichiChang 好的呢 🍺 |
|
||
An app that displays [issues from the flutter GitHub repository](https://github.com/flutter/flutter/issues) sounds reasonable to me for the sake of this demo. | ||
实现一个展示 [issues from the flutter GitHub repository](https://github.com/flutter/flutter/issues) 的 demo。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『实现一个展示 [issues from the flutter GitHub repository]』→『实现一个展示 [Flutter Issue 列表]』
|
||
#### Model | ||
|
||
It’s just a simple class for holding some info about a Github issue. It also can initialize itself from a piece of JSON. | ||
Model 只是包含 Github issue 信息的一个简单的类。它也可以通过一段 JSON 来初始化它自身。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『Model 只是包含 Github issue 信息的一个简单的类。』→『Model 只是一个包含 Github issue 信息的简单的类。』
@@ -53,7 +53,7 @@ class GithubIssue { | |||
|
|||
#### State | |||
|
|||
There is not so much data that we’ll need to keep inside the state: the list of items, the flags indicating whether the data is being loaded and whether there is more data available, and the error. | |||
在这里我们需要在 state 中记录的数据并不多:issues 列表,声明数据是否被载入以及是否还有更多数据的 flag 以及错误信息。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『在这里我们需要在 state 中记录的数据并不多:issues 列表,声明数据是否被载入以及是否还有更多数据的 flag 以及错误信息。』→『我们需要在 state 中记录的数据并不多:一个包含多个 issue 的列表,一个数据是否被载入的标志位,一个是否还有更多数据的标志位以及错误信息。』
@@ -143,6 +144,7 @@ class ErrorHandledAction {} | |||
#### Reducers | |||
|
|||
The reducers that create a new state based on a received action are a bit more complicated than actions, but only a bit. They are just simple pure functions that are combined by the `combineReducers` function the library gives us. | |||
基于接收到的 action 新建一个 state 的 reducers 会比 actions 更复杂一点,但是也并没有复杂很多。它们其实就是一些由库提供的 `combineReducers` 函数结合起来的纯函数而已。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『一些由库提供』→『一些由 Redux 库提供』
@@ -143,6 +144,7 @@ class ErrorHandledAction {} | |||
#### Reducers | |||
|
|||
The reducers that create a new state based on a received action are a bit more complicated than actions, but only a bit. They are just simple pure functions that are combined by the `combineReducers` function the library gives us. | |||
基于接收到的 action 新建一个 state 的 reducers 会比 actions 更复杂一点,但是也并没有复杂很多。它们其实就是一些由库提供的 `combineReducers` 函数结合起来的纯函数而已。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『基于接收到的 action 新建一个 state 的 reducers 会比 actions 更复杂一点』→『Reducer 会根据接收到的 action 创建新的 state,它会比 action 复杂一点』
@@ -207,7 +209,7 @@ Exception _errorHandledReducer(Exception _, ErrorHandledAction action) { | |||
|
|||
#### Middleware | |||
|
|||
The implemented middleware basically consists of the function that tries to load data from the API and posts either the successful action or the action indicating a failure. | |||
这里使用的 middleware 基本上是由从 API 加载数据和发送成功 action 和失败 action 的方法构成的。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『这里使用的 middleware 基本上是由从 API 加载数据和发送成功 action 和失败 action 的方法构成的。』→『Middleware 是由从 API 加载数据的函数和发送成功或失败的 action 构成的。』
3. `RefreshIndicator` that helps us significantly to get the so-called “pull-to-refresh” feature. | ||
4. `ErrorNotifier` that is responsible for showing a toast notification in case an error occurs. If you need more details on this one, take a look [at my previous article](https://medium.com/flutter-community/flutter-redux-toast-notification-fcd0971eaf0f). | ||
1. 页面包含了 `ScrollController` 来决定是否需要调用 `loadNextPage` 函数。 | ||
2. 在这里使用了 `Debouncer`(具体实现见下文)。它是带有计时器的一个小类,能够确保来自 `ScrollController` 的连续事件不会触发大量的下一页请求,而是在一个特定时间段之内只发送一次请求。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『它是带有计时器的一个小类』→『它是一个包含定时器功能的简单类』
2. Something called `Debouncer` is used (the implementation you’ll see below). It’s just a tiny class with a timer inside it that ensures that consecutive events from the `ScrollController` won’t create tons of requests for a next page, but rather the only request will be made in the specified period of time. | ||
3. `RefreshIndicator` that helps us significantly to get the so-called “pull-to-refresh” feature. | ||
4. `ErrorNotifier` that is responsible for showing a toast notification in case an error occurs. If you need more details on this one, take a look [at my previous article](https://medium.com/flutter-community/flutter-redux-toast-notification-fcd0971eaf0f). | ||
1. 页面包含了 `ScrollController` 来决定是否需要调用 `loadNextPage` 函数。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『页面包含了 ScrollController
来决定』→『Screen 依赖 ScrollController
来决定』
4. `ErrorNotifier` that is responsible for showing a toast notification in case an error occurs. If you need more details on this one, take a look [at my previous article](https://medium.com/flutter-community/flutter-redux-toast-notification-fcd0971eaf0f). | ||
1. 页面包含了 `ScrollController` 来决定是否需要调用 `loadNextPage` 函数。 | ||
2. 在这里使用了 `Debouncer`(具体实现见下文)。它是带有计时器的一个小类,能够确保来自 `ScrollController` 的连续事件不会触发大量的下一页请求,而是在一个特定时间段之内只发送一次请求。 | ||
3. `RefreshIndicator` 可以提醒我们使用『下拉刷新』功能。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『提醒我们使用『下拉刷新』功能』→『在我们使用『下拉刷新』功能时给予提示』
@Glowin @XatMassacrE 校对完成 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
做了一点调整记得更新一下。
@XatMassacrE 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。 掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件。 |
译文翻译完成,resolve #6380