Skip to content

Commit dffd290

Browse files
authored
Merge pull request #179 from Huynt-dev/2013-06-05-why-react.md
translate english to vietnamese 2013-06-05-why-react
2 parents bf0f9f0 + 9a7d78b commit dffd290

File tree

1 file changed

+51
-76
lines changed

1 file changed

+51
-76
lines changed
Lines changed: 51 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,63 @@
11
---
2-
title: Why did we build React?
2+
title: Tại sao chúng tôi xây dựng React?
33
author: [petehunt]
44
---
55

6-
There are a lot of JavaScript MVC frameworks out there. Why did we build React
7-
and why would you want to use it?
6+
Có rất nhiều thư viện JavaScript MVC. Tại sao chúng tôi xây dựng React và tại sao bạn muốn sử dụng nó?
87

9-
## React isn't an MVC framework. {#react-isnt-an-mvc-framework}
8+
## React không phải là một MVC framework. {#react-isnt-an-mvc-framework}
109

11-
React is a library for building composable user interfaces. It encourages
12-
the creation of reusable UI components which present data that changes over
13-
time.
10+
React là một thư viện để xây dựng giao diện người dùng. Nó khuyến khích việc tạo ra các thành phần giao diện người dùng có thể tái sử dụng, hiển thị dữ liệu thay đổi theo thời gian.
1411

1512
## React doesn't use templates. {#react-doesnt-use-templates}
1613

17-
Traditionally, web application UIs are built using templates or HTML directives.
18-
These templates dictate the full set of abstractions that you are allowed to use
19-
to build your UI.
20-
21-
React approaches building user interfaces differently by breaking them into
22-
**components**. This means React uses a real, full featured programming language
23-
to render views, which we see as an advantage over templates for a few reasons:
24-
25-
- **JavaScript is a flexible, powerful programming language** with the ability
26-
to build abstractions. This is incredibly important in large applications.
27-
- By unifying your markup with its corresponding view logic, React can actually
28-
make views **easier to extend and maintain**.
29-
- By baking an understanding of markup and content into JavaScript, there's
30-
**no manual string concatenation** and therefore less surface area for XSS
31-
vulnerabilities.
32-
33-
We've also created [JSX](/docs/jsx-in-depth.html), an optional syntax
34-
extension, in case you prefer the readability of HTML to raw JavaScript.
35-
36-
## Reactive updates are dead simple. {#reactive-updates-are-dead-simple}
37-
38-
React really shines when your data changes over time.
39-
40-
In a traditional JavaScript application, you need to look at what data changed
41-
and imperatively make changes to the DOM to keep it up-to-date. Even AngularJS,
42-
which provides a declarative interface via directives and data binding [requires
43-
a linking function to manually update DOM nodes](https://code.angularjs.org/1.0.8/docs/guide/directive#reasonsbehindthecompilelinkseparation).
44-
45-
React takes a different approach.
46-
47-
When your component is first initialized, the `render` method is called,
48-
generating a lightweight representation of your view. From that representation,
49-
a string of markup is produced, and injected into the document. When your data
50-
changes, the `render` method is called again. In order to perform updates as
51-
efficiently as possible, we diff the return value from the previous call to
52-
`render` with the new one, and generate a minimal set of changes to be applied
53-
to the DOM.
54-
55-
> The data returned from `render` is neither a string nor a DOM node -- it's a
56-
> lightweight description of what the DOM should look like.
57-
58-
We call this process **reconciliation**. Check out
59-
[this jsFiddle](http://jsfiddle.net/2h6th4ju/) to see an example of
60-
reconciliation in action.
61-
62-
Because this re-render is so fast (around 1ms for TodoMVC), the developer
63-
doesn't need to explicitly specify data bindings. We've found this approach
64-
makes it easier to build apps.
65-
66-
## HTML is just the beginning. {#html-is-just-the-beginning}
67-
68-
Because React has its own lightweight representation of the document, we can do
69-
some pretty cool things with it:
70-
71-
- Facebook has dynamic charts that render to `<canvas>` instead of HTML.
72-
- Instagram is a "single page" web app built entirely with React and
73-
`Backbone.Router`. Designers regularly contribute React code with JSX.
74-
- We've built internal prototypes that run React apps in a web worker and use
75-
React to drive **native iOS views** via an Objective-C bridge.
76-
- You can run React
77-
[on the server](https://github.com/petehunt/react-server-rendering-example)
78-
for SEO, performance, code sharing and overall flexibility.
79-
- Events behave in a consistent, standards-compliant way in all browsers
80-
(including IE8) and automatically use
14+
Theo truyền thống, giao diện người dùng ứng dụng web được xây dựng bằng cách sử dụng các templates hoặc HTML.
15+
Các templates này quy định tập hợp đầy đủ các phần tóm tắt mà bạn được phép sử dụng để xây dựng giao diện người dùng của mình.
16+
17+
React tiếp cận việc xây dựng các giao diện người dùng theo cách chia nhỏ chúng thành các
18+
**components**. Điều này có nghĩa là React sử dụng một ngôn ngữ lập trình, đầy đủ tính năng để hiển thị các chế độ xem, mà chúng tôi coi là một lợi thế hơn so với các templates vì một số lý do:
19+
20+
- **JavaScript là một ngôn ngữ lập trình linh hoạt, mạnh mẽ** với khả năng xây dựng sự trừu tượng. Điều này cực kỳ quan trọng trong các ứng dụng lớn.
21+
- Bằng cách thống nhất đánh dấu của bạn với logic chế độ xem tương ứng của nó, React thực sự có thể tạo các chế độ xem **dễ dàng mở rộng và bảo trì hơn**.
22+
- Bằng cách đưa hiểu biết về markup và content vào JavaScript,
23+
**không có quá trình nối chuỗi thủ công** và do đó ít diện tích bề mặt hơn cho các lỗ hổng XSS.
24+
25+
Chúng tôi cũng đã tạo [JSX](/docs/jsx-in-depth.html), một phần mở rộng cú pháp tùy chọn, trong trường hợp bạn thích khả năng đọc của HTML hơn JavaScript thô.
26+
27+
## Cập nhật phản ứng rất đơn giản {#reactive-updates-are-dead-simple}
28+
29+
React thực sự nổi bật khi dữ liệu của bạn thay đổi theo thời gian.
30+
31+
Trong một ứng dụng JavaScript truyền thống, bạn cần xem dữ liệu nào đã thay đổi và thực hiện các thay đổi theo thứ bậc đối với DOM để luôn cập nhật. Ngay cả AngularJS, cung cấp giao diện khai báo thông qua các chỉ thị và liên kết dữ liệu [yêu cầu một chức năng liên kết để cập nhật các nút DOM theo cách thủ công.](https://code.angularjs.org/1.0.8/docs/guide/directive#reasonsbehindthecompilelinkseparation).
32+
33+
React có một cách tiếp cận khác.
34+
35+
Khi component của bạn được khởi tạo lần đầu tiên, phương thức `render` được gọi,
36+
nó tạo ra 1 phiên bản UI rất nhỏ. Từ phiên bản này, nó sẽ tạo thành 1 chuỗi html(markup) và cập nhật(replace?) document hiện tại. Mỗi khi dữ liệu(prop, …) của app thay đổi, phương thức `render` lại được gọi lại. Để quá trình re-render và update lại dom hiệu quả nhất, chúng tôi check sự thay đổi giữa lần thay đổi trước và sau `render`, và chỉ lấy ra đoạn code đã thay đổi và cập nhật lại DOM (không cập nhật lại toàn bộ)
37+
38+
39+
> Dữ liệu sinh ra sau quá trình `render` không hẳn là 1 chuỗi hay là 1 DOM node cụ thể, nó là 1 dạng tập hợp các mô tả về DOM.
40+
41+
Chúng tôi gọi quá trình này là **reconciliation**. Tham khảo
42+
[this jsFiddle](http://jsfiddle.net/2h6th4ju/) này để xem ví dụ về
43+
reconciliation trong thực tế.
44+
45+
Vì quá trình kết xuất này quá nhanh (khoảng 1ms đối với TodoMVC), nhà phát triển không cần chỉ định rõ ràng các ràng buộc dữ liệu. Chúng tôi nhận thấy cách tiếp cận này giúp tạo ứng dụng dễ dàng hơn.
46+
47+
## HTML chỉ là sự khởi đầu {#html-is-just-the-beginning}
48+
49+
Bởi vì React có bản trình bày tài liệu gọn nhẹ của riêng nó, chúng ta có thể thực hiện một số điều khá thú vị với nó:
50+
51+
- Facebook có các biểu đồ động hiển thị dưới dạng `<canvas>` thay vì HTML.
52+
- Instagram là một ứng dụng web "một trang" được xây dựng hoàn toàn bằng React và `Backbone.Router`. Các nhà thiết kế thường xuyên đóng góp mã React với JSX.
53+
- Chúng tôi đã xây dựng internal prototypes để chạy các ứng dụng React trong web worker và sử dụng React để thúc đẩy **native iOS views** qua một Objective-C
54+
- Bạn có thể chạy React
55+
[trên máy chủ](https://github.com/petehunt/react-server-rendering-example)
56+
để SEO, hiệu suất, chia sẻ mã và tính linh hoạt tổng thể.
57+
- Các sự kiện hoạt động theo cách nhất quán, tuân thủ tiêu chuẩn trong tất cả các trình duyệt (bao gồm cả IE8) và tự động sử dụng
8158
[event delegation](http://davidwalsh.name/event-delegate).
8259

83-
Head on over to [https://reactjs.org](https://reactjs.org) to check out what we have
84-
built. Our documentation is geared towards building apps with the framework,
85-
but if you are interested in the nuts and bolts
86-
[get in touch](/support.html) with us!
60+
Truy cập [https://reactjs.org](https://reactjs.org) để kiểm tra những gì chúng tôi đã xây dựng. Tài liệu của chúng tôi hướng tới việc xây dựng ứng dụng với framework, nhưng nếu bạn quan tâm đến những chi tiết cần thiết
61+
[liên hệ](/support.html) với chúng tôi!
8762

88-
Thanks for reading!
63+
Cảm ơn vì đã đọc!

0 commit comments

Comments
 (0)