Skip to content
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

Conversation

XatMassacrE
Copy link
Contributor

译文翻译完成,resolve #6380

@TsichiChang
Copy link

校对认领 @Glowin

@fanyijihua
Copy link
Collaborator

@TsichiChang 好的呢 🍺

TODO1/flutter-infinite-listview-with-redux.md Outdated Show resolved Hide resolved

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

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 来初始化它自身。

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 以及错误信息。

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` 函数结合起来的纯函数而已。

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` 函数结合起来的纯函数而已。

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 的方法构成的。

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` 的连续事件不会触发大量的下一页请求,而是在一个特定时间段之内只发送一次请求。

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` 函数。

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` 可以提醒我们使用『下拉刷新』功能。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『提醒我们使用『下拉刷新』功能』→『在我们使用『下拉刷新』功能时给予提示』

@TsichiChang
Copy link

@Glowin @XatMassacrE 校对完成

TsichiChang
TsichiChang previously approved these changes Oct 21, 2019
@sunui sunui added 标注 待管理员 Review and removed 校对认领 正在校对 labels Oct 29, 2019
Copy link
Contributor

@sunui sunui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

做了一点调整记得更新一下。

@lsvih lsvih merged commit f1c9a7a into xitu:master Nov 15, 2019
@lsvih
Copy link
Member

lsvih commented Nov 15, 2019

@XatMassacrE 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。

掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件
专栏地址:https://zhuanlan.zhihu.com/juejinfanyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flutter: 使用 Redux 实现无限 ListView
5 participants