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

使用 Recompose 来构建高阶组件 #5025

Merged
merged 9 commits into from
Jan 23, 2019
Merged

使用 Recompose 来构建高阶组件 #5025

merged 9 commits into from
Jan 23, 2019

Conversation

SHERlocked93
Copy link
Contributor

@SHERlocked93 SHERlocked93 commented Jan 20, 2019

译文翻译完成,resolve #5019

@Eternaldeath
Copy link

校对认领

@fanyijihua
Copy link
Collaborator

@Eternaldeath 好的呢 🍺

@seanzhou1996
Copy link

校对认领

@fanyijihua
Copy link
Collaborator

@SeanZhouSiyuan 妥妥哒 🍻

* Easily Mocked — Easily mock props for different situations
* 模块化代码 - 可以在整个项目范围内复用你的代码段;
* 只依赖于 props - 默认没有 state;
* 更便于单元测试 - 对 enzyme/jest 更友好的测试接口;

Choose a reason for hiding this comment

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

含义不清晰:只看译文的话,对 enzyme/jest 陌生的读者,可能无法理解这句话的意思。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

改为:对测试工具 enzyme/jest 更友好的测试接口


#### Step 3 — Get your state right
#### 步骤3 - 正确

Choose a reason for hiding this comment

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

只看标题的话,含义不明确。可改为“确保 state 无误”或类似译法。

@@ -162,15 +162,15 @@ export default compose(
)(Presentation);
```

Here we setup the state key `isVisible` , we setup a method to `toggleVis` and an initial state of false.
这里我们设置了状态属性 `isVisible`,一个控制可见性的方法 `toggleVis`,和一个初始值 false

Choose a reason for hiding this comment

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

此段原文中的两处 state,是否与先前的 state 含义相同?如果是的话,需要统一译法。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

seanzhou1996
seanzhou1996 previously approved these changes Jan 22, 2019
Copy link

@seanzhou1996 seanzhou1996 left a comment

Choose a reason for hiding this comment

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

校对完毕,译者修改完成,顺便 @leviding 之前忘记了 LOL

Copy link

@Eternaldeath Eternaldeath left a comment

Choose a reason for hiding this comment

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

翻译的很好,提出了一些小小的改动。

* Can add “state” to any component which means you don’t have to rely Redux for everything (if you are doing so now)
* Manipulate the props you send down to the Presentational Component (map, reduce, w/e you want!)
* 可以给其他的展示型组件进行相同的代码复用;
* 简化可读性较差的臃肿的组件;

Choose a reason for hiding this comment

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

『简化可读性较差的臃肿的组件』=>『清理可读性较差的臃肿的组件』

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里清理可能容易歧义


And there we were, digging the pattern, and off to the races. We hit a couple problems along the way. It became super tedious to constantly write the same HOC syntax for simple things, we didn’t have patterns for combining multiple enhancers together, and we couldn’t prevent the development of duplicate enhancers (this annoys me the most, but I know happens). It was getting hard to prove the value of this pattern as people were getting bogged down in the syntax and the ideas of HOCs (much like engineers do).
然后我们开始在生产环境中深度使用高阶组件了,并在使用过程中遇到了几个问题。比如为简单的场景不断地编写简单地高阶组件就很无聊,没有将多个高阶组件进行合成的方法,也无法避免开发出冗余的高阶组件(这个最麻烦,但我清楚这有时确实会发生)。人们逐渐陷入高阶组件的语法和观念中寸步难行,这种模式似乎也已渐渐失去了价值。

Choose a reason for hiding this comment

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

1.much like engineers do 没有翻译出来
2.『这种模式似乎也已渐渐失去了价值』=>『很难证明这种模式的价值』

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改


`withHandlers` create higher-order functions that accept a set of props and return a function handler, in this case responsible for toggling visibility state. The `toggleVisibility` function will be available to our Presentation component as a prop.
`withHandlers` 创建了一个高阶组件,它接受一系列 `props` 并返回一个处理函数,在这个例子中是处理可见性 `state` 的函数。`toggleVisibility` 这个函数将作为 `Presentation` 组件的一个 `prop`。

Choose a reason for hiding this comment

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

『在这个例子中是处理可见性 state 的函数』=>『在这个例子中是切换可见性 state 的函数』

@Eternaldeath
Copy link

校对完毕

@SHERlocked93
Copy link
Contributor Author

@Eternaldeath @SeanZhouSiyuan 非常感谢校对,辛苦了~

@leviding 已根据校对意见修改

@leviding leviding added the 标注 待管理员 Review label Jan 23, 2019
@leviding leviding added 翻译完成 and removed 标注 待管理员 Review 正在校对 labels Jan 23, 2019
@leviding leviding merged commit 0dc6ef4 into xitu:master Jan 23, 2019
@leviding
Copy link
Member

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

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

@SHERlocked93
Copy link
Contributor Author

@leviding 已经发布啦,地址: https://juejin.im/post/5c484a43e51d452ec621b6a9

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.

使用 Recompose 来构建高阶组件
5 participants