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

在 SnackBar,Navigation 和其他事件中使用 LiveData(SingleLiveEvent 案例) #3945

Conversation

wzasd
Copy link
Contributor

@wzasd wzasd commented Jun 5, 2018

译文翻译完成,resolve #3894
@leviding

@leviding leviding changed the title Translation/live data with snack bar, navigation and other events (the single live event case 在 SnackBar,Navigation 和其他事件中使用 LiveData(SingleLiveEvent 案例) Jun 5, 2018
@LeeSniper
Copy link
Contributor

校对认领

@fanyijihua
Copy link
Collaborator

@LeeSniper 好的呢 🍺

Copy link
Contributor

@LeeSniper LeeSniper left a comment

Choose a reason for hiding this comment

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

指出了一些感觉翻译上可能不太准确的地方,希望可以采纳。排版方面很好,我没发现什么排版方面的问题,我校对过的文章多多少少都有些排版问题,这篇做的的确很好。

> * 校对者:

## LiveData with SnackBar, Navigation and other events (the SingleLiveEvent case)
## 在 SnackBar,Navigation 和其他事件中使用 LiveData(SingleLiveEvent 案例)

Copy link
Contributor

Choose a reason for hiding this comment

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

多了一个空行,导致排版格式有点不对,对照 File changed 页面稍微调整一下。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个有些不理解


![](https://cdn-images-1.medium.com/max/800/1*WwhYg9sscdYQgLvC3xks4g.png)

Instead of trying to solve this with libraries or extensions to the Architecture Components, it should be faced as a design problem. **We recommend you treat your events as part of your state**. In this article we show some common mistakes and recommended approaches.
这应该考虑设计问题,而不是试图通过架构组件的裤或者扩展来解决这个问题。**我们建议您将您的事件视为您的状态的一部分**。在本文中,我们将展示一些常见的错误方法,以及推荐的方式。
Copy link
Contributor

Choose a reason for hiding this comment

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

应该考虑设计问题 => 应该被视为设计问题


![](https://cdn-images-1.medium.com/max/800/1*WwhYg9sscdYQgLvC3xks4g.png)

Instead of trying to solve this with libraries or extensions to the Architecture Components, it should be faced as a design problem. **We recommend you treat your events as part of your state**. In this article we show some common mistakes and recommended approaches.
这应该考虑设计问题,而不是试图通过架构组件的裤或者扩展来解决这个问题。**我们建议您将您的事件视为您的状态的一部分**。在本文中,我们将展示一些常见的错误方法,以及推荐的方式。
Copy link
Contributor

Choose a reason for hiding this comment

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

裤 => 库


This approach holds a Snackbar message or a navigation signal directly inside a LiveData object. Although in principle it seems like a regular LiveData object can be used for this, it presents some problems.
这种方法来直接的在 LiveData 对象的内部来持有 Snackbar 消息或者导航一些信息。尽管原则上看起来像是普通的 LiveData 对象可以用在这里,但是会出现一些问题。
Copy link
Contributor

Choose a reason for hiding this comment

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

导航一些信息 => 导航信息


This approach holds a Snackbar message or a navigation signal directly inside a LiveData object. Although in principle it seems like a regular LiveData object can be used for this, it presents some problems.
这种方法来直接的在 LiveData 对象的内部来持有 Snackbar 消息或者导航一些信息。尽管原则上看起来像是普通的 LiveData 对象可以用在这里,但是会出现一些问题。
Copy link
Contributor

Choose a reason for hiding this comment

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

来持有 => 持有


The problem with this approach is that there’s some boilerplate (one new method in the ViewModel per event) and it’s error prone; it’s easy to forget the call to the ViewModel from the observer.
这种方法的问题是有一些样板(每个事件在 ViewModel 中有一个新的方法),并且很容易出错,观察者很容易忘记调用这个 ViewModel 的方法。
Copy link
Contributor

Choose a reason for hiding this comment

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

样板 => 死板,虽然 boilerplate 的意思就是样板、模板,但是这里是在指出这种方法中存在的问题,所以翻译成“死板”语义方面感觉更通顺


![](https://cdn-images-1.medium.com/max/800/1*b0z9Flj04zVW_UGsDPQyOA.png)

With an Event wrapper, you can add multiple observers to a single-use event
使用事件包装器,您可以将多个观察器添加到一次性事件中。
Copy link
Contributor

Choose a reason for hiding this comment

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

观察器 => 观察者


* * *

In summary: **design events as part of your state**. Use your own [Event](https://gist.github.com/JoseAlcerreca/5b661f1800e1e654f07cc54fe87441af) wrapper in LiveData observables and customize it to fit your needs.
总之:**设计事件作为你的状态的一部分**。使用您自己的[事件](https://gist.github.com/JoseAlcerreca/5b661f1800e1e654f07cc54fe87441af)包装器并根据您的需求进行定制。
Copy link
Contributor

Choose a reason for hiding this comment

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

设计事件作为 => 把事件设计成


* * *

In summary: **design events as part of your state**. Use your own [Event](https://gist.github.com/JoseAlcerreca/5b661f1800e1e654f07cc54fe87441af) wrapper in LiveData observables and customize it to fit your needs.
总之:**设计事件作为你的状态的一部分**。使用您自己的[事件](https://gist.github.com/JoseAlcerreca/5b661f1800e1e654f07cc54fe87441af)包装器并根据您的需求进行定制。

Bonus! Use this [EventObserver](https://gist.github.com/JoseAlcerreca/e0bba240d9b3cffa258777f12e5c0ae9) to remove some repetitive code if you end up having lots of events.
Copy link
Contributor

Choose a reason for hiding this comment

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

这段英文没有删除


Bonus! Use this [EventObserver](https://gist.github.com/JoseAlcerreca/e0bba240d9b3cffa258777f12e5c0ae9) to remove some repetitive code if you end up having lots of events.
银弹!若您最终发生大量事件,请使用这个 [EventObserver](https://gist.github.com/JoseAlcerreca/e0bba240d9b3cffa258777f12e5c0ae9) 可以删除很多无用的代码。
Copy link
Contributor

Choose a reason for hiding this comment

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

bonus 的意思是额外奖励,我想不到一个更合适的中文译词,不过这里为什么翻译成 “银弹” 呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

银弹就是程序猿的额外奖励呀~~

@LeeSniper
Copy link
Contributor

@wzasd @leviding 校对完成

@leviding
Copy link
Member

leviding commented Jun 11, 2018

@wzasd 修改吧,就一位校对可以了。

@wzasd
Copy link
Contributor Author

wzasd commented Jun 11, 2018

@leviding 已修改完善

Copy link
Member

@leviding leviding left a comment

Choose a reason for hiding this comment

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

@wzasd 还有些问题,校对者意见要看全。还有十几条意见没有修改。


In a master/detail app, here is the master’s ViewModel:
在一个主/从应用程序中,这里是主 ViewModel

```
// Don't use this for events
Copy link
Member

Choose a reason for hiding this comment

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

@wzasd 注释需要翻译

2. The user presses back, coming back to the master activity
3. The observers become active again, after being inactive while activity was in the back stack
4. The value is still `true` so the Details activity is incorrectly started again
5. 用户点击按钮 Details Activity 启动。
Copy link
Member

Choose a reason for hiding this comment

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

@wzasd 编号问题注意看

@@ -2,26 +2,26 @@
> * 原文作者:[Jose Alcérreca](https://medium.com/@JoseAlcerreca?source=post_header_lockup)
> * 译文出自:[掘金翻译计划](https://github.com/xitu/gold-miner)
> * 本文永久链接:[https://github.com/xitu/gold-miner/blob/master/TODO1/livedata-with-snackbar-navigation-and-other-events-the-singleliveevent-case.md](https://github.com/xitu/gold-miner/blob/master/TODO1/livedata-with-snackbar-navigation-and-other-events-the-singleliveevent-case.md)
> * 译者:
> * 译者:[wzasd](github.com/wzasd)
> * 校对者:
Copy link
Member

Choose a reason for hiding this comment

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

校对者信息

@leviding leviding added the enhancement 等待译者修改 label Jun 11, 2018
@wzasd
Copy link
Contributor Author

wzasd commented Jun 11, 2018

@LeeSniper @leviding 感谢指正~

@leviding leviding merged commit 5ee4758 into xitu:master Jun 12, 2018
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.

在 SnackBar,Navigation 和其他事件中使用 LiveData(SingleLiveEvent 案例)
4 participants