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

docs(cn): translate content/blog/2014-05-06-flux.md into Chinese #916

Merged
merged 5 commits into from
Oct 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions content/blog/2014-05-06-flux.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
title: "Flux: An Application Architecture for React"
title: "Flux:一个用于 React 的应用架构"
author: [fisherwebdev, jingc]
---

We recently spoke at one of f8's breakout session about Flux, a data flow architecture that works well with React. Check out the video here:
我们最近在 F8 大会(Facebook 于 2014.4.30 召开的开发者大会)的一个分组会议上交流了 Flux,一个与 React 配合的很好的数据流架构。在这里可查看视频:

<figure><iframe width="650" height="315" src="//www.youtube-nocookie.com/embed/nYkdrAPrdcw?list=PLb0IAmt7-GS188xDYE-u1ShQmFFGbrk0v&start=621" frameborder="0" allowfullscreen></iframe></figure>

To summarize, Flux works well for us because the single directional data flow makes it easy to understand and modify an application as it becomes more complicated. We found that two-way data bindings lead to cascading updates, where changing one data model led to another data model updating, making it very difficult to predict what would change as the result of a single user interaction.
总而言之,Flux 很适合我们,因为单向数据流模式可以使一个项目在日益复杂时变的更容易理解和维护。我们发现双向数据绑定会使得级联更新,无论在哪修改其中一个数据模型会导致另一个数据模型也更新,因此很难预测单个用户交互时会导致什么变化。

In Flux, the Dispatcher is a singleton that directs the flow of data and ensures that updates do not cascade. As an application grows, the Dispatcher becomes more vital, as it can also manage dependencies between stores by invoking the registered callbacks in a specific order.
Flux 中,Dispatcher 是单例的,它指向数据流并保证更新时不会级联更新。随着应用扩大,Dispatcher 越来越重要,因为它可以通过特定顺序调用注册的回调来管理 store 之间的依赖关系。

When a user interacts with a React view, the view sends an action (usually represented as a JavaScript object with some fields) through the dispatcher, which notifies the various stores that hold the application's data and business logic. When the stores change state, they notify the views that something has updated. This works especially well with React's declarative model, which allows the stores to send updates without specifying how to transition views between states.
当用户在 React 视图中产生交互时,视图会发送一个 action(通常是一些带有字段属性的 JavaScript 对象)传至 dispatcher 中,dispatcher 会通知 store 保存应用数据和处理业务逻辑。当 store 修改完了 state 数据,它们会通知视图组件已经更新。这种模式与 React 的声明式配合的很好,它允许 store 发送数据更新而无需关注视图和数据之间是如何转换更新的。

Flux is more of a pattern than a formal framework, so you can start using Flux immediately without a lot of new code. An [example of this architecture](https://github.com/facebook/flux/tree/master/examples/flux-todomvc) is available, along with more [detailed documentation](https://facebook.github.io/flux/docs/overview.html) and a [tutorial](https://github.com/facebook/flux/tree/main/examples/flux-todomvc). Look for more examples to come in the future.
Flux 更像是一种模式,而不是一个常规的框架,所以你可以在不添加大量新代码的情况下立即使用 Flux。这里提供了一个 [架构的示例](https://github.com/facebook/flux/tree/master/examples/flux-todomvc) ,同时还有 [更详细的文档](https://facebook.github.io/flux/docs/overview.html) 和 [教程](https://facebook.github.io/flux/docs/todo-list.html) ,可以在文档中查看更多的示例。