diff --git a/.DS_Store b/.DS_Store
deleted file mode 100644
index 84f5661..0000000
Binary files a/.DS_Store and /dev/null differ
diff --git a/.gitignore b/.gitignore
index 13745c9..c1d09b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,3 +38,7 @@ jspm_packages
./code/node_modules
./code/*.log
+
+.DS_Store
+
+*~
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..afbc4ed
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,6 @@
+# Contributting to React in Patterns (Thai Edition)
+หนังสือ "React in Patterns (ฉบับภาษาไทย)" ได้ขออนุญาตกับทางผู้เขียนเพื่อทำการแปลเป็นภาษาไทยเรียบร้อยแล้ว หากต้องการร่วม contribute หรือแก้ไขข้อผิดพลาดประการใด ทางทีมผู้แปลยินดีเป็นอย่างยิ่ง
+
+## แปลไทยโดย
+- [React Bangkok](https://github.com/reactbkk)
+- [Athiwat Hirunworawongkun](https://github.com/athivvat)
\ No newline at end of file
diff --git a/README.md b/README.md
index 74b1c53..830033c 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,11 @@
-# React in patterns
+# React in patterns (ฉบับภาษาไทย)
-:books: A free book that talks about design patterns/techniques used while developing with [React](https://facebook.github.io/react/).
+:books: หนังสือแจกฟรีที่อธิบายเกี่ยวกับดีไซน์แพตเทิร์นและเทคนิคที่ใช้สำหรับการพัฒนาเว็บแอพพลิเคชันด้วย [React](https://facebook.github.io/react/).
-## Book
+## ผู้เขียน
+[Krasimir Tsonev](https://github.com/krasimir)
+
+## หนังสือ
* [GitBook](https://www.gitbook.com/book/krasimir/react-in-patterns/details)
* [Web](https://krasimir.gitbooks.io/react-in-patterns/content/)
@@ -12,11 +15,11 @@

-## Content
+## สารบัญ
-* [In brief](./book/chapter-1/README.md)
+* [เนื้อหาโดยสังเขป](./book/chapter-1/README.md)
-### Foundation
+### หลักการพื้นฐาน (Foundation)
* [Communication](./book/chapter-2/README.md)
* [Input](./book/chapter-2/README.md#input)
@@ -30,7 +33,7 @@
* [Controlled and uncontrolled inputs](./book/chapter-5/README.md)
* [Presentational and container components](./book/chapter-6/README.md)
-### Data flow
+### กระแสข้อมูล (Data flow)
* [One direction data flow](./book/chapter-7/README.md)
* [Flux](./book/chapter-8/README.md)
@@ -54,11 +57,11 @@
* [Integration of third-party libraries](./book/chapter-12/README.md)
-## Source code
+## ซอร์สโค้ด
-The code samples used in the book are available [here](./code).
+ตัวอย่างซอร์สโค้ดที่ใช้ประกอบในหนังสือเล่มนี้ สามารถดาวน์โหลดได้ที่ [ตัวอย่างซอร์สโค้ด](./code).
-## Other resources
+## แหล่งข้อมูลอ้างอิงอื่นๆ
* [React Design principles](https://facebook.github.io/react/contributing/design-principles.html)
* [Airbnb React/JSX Style Guide](https://github.com/airbnb/javascript/tree/master/react)
diff --git a/_config.yml b/_config.yml
new file mode 100644
index 0000000..c419263
--- /dev/null
+++ b/_config.yml
@@ -0,0 +1 @@
+theme: jekyll-theme-cayman
\ No newline at end of file
diff --git a/assets/cover.jpg b/assets/cover.jpg
index eb7caa2..65da89f 100644
Binary files a/assets/cover.jpg and b/assets/cover.jpg differ
diff --git a/assets/cover.psd b/assets/cover.psd
index 9c37f35..e244478 100644
Binary files a/assets/cover.psd and b/assets/cover.psd differ
diff --git a/book/chapter-1/README.md b/book/chapter-1/README.md
index a5ade24..fdec633 100644
--- a/book/chapter-1/README.md
+++ b/book/chapter-1/README.md
@@ -1,7 +1,7 @@
-# In brief
-This cookbook is targeting developers that already have basic understanding of what React is and how it works. It's not meant to be used as a complete how-to guide but as an introduction to popular concepts/design patterns. Paradigms that more or less are introduced by the community. It points you to an abstract thinking. For example, instead of talking about Flux, it talks about data flow. Instead of talking about higher-order components it talks about composition.
+# เนื้อหาโดยสังเขป
-The book is highly opinioned. It represents my own understanding of the described patterns and it is possible that they have a different interpretation around the web. Have this in mind when arguing with someone and using this book as an argument.
-
-Also notice that English is not my native language. If you see a typo or something sounds weird please contribute here [github.com/krasimir/react-in-patterns](https://github.com/krasimir/react-in-patterns/tree/master/book). If you read from a printed version of this book then feel free to use a pen ¯\\_(ツ)_/¯
+ หนังสือเล่มนี้เล็งเป้าหมายไปที่นักเขียนโปรแกรมที่มีความรู้ความเข้าใจพื้นฐานรวมถึงการทำงานของ React อยู่แล้ว โดยที่ไม่ได้หวังว่าจะหนังสือเล่มนี้จะเป็นหนังสือที่กำหนดแนวทางในการเขียนโปรแกรม แต่หวังว่าจะเป็นจุดเริ่มต้นในการศึกษา แนวคิด/รูปแบบ ของการเขียน React
+ ตัวอย่างไม่มากก็น้อยที่ถูกนำเสนอโดยชุมชนนักพัฒนาชี้ให้เห็นถึงการคิดแบบเชิงนามธรรม เช่น แทนที่จะพูดเกี่ยวกับ Flux หนังสือเล่มนี้จะพูดถึง data flow หรือแทนที่จะพูดถึง higher-order components หนังสือเล่มนี้จะพูดถึง composition แทน
+
+ หนังสือเล่มนี้ค่อนข้างเป็นมุมมองส่วนตัว ซึ่งแสดงถึงความเข้าใจของผู้เขียนต่อรูปแบบการเขียนโปรแกรมที่ถูกกล่าวถึง เพราะฉะนั้นเป็นไปได้ที่จะมีการตีความที่แตกต่างแบบอื่น ๆ อยู่ทั่วไปในอินเตอร์เน็ต ขอให้ผู้อ่านทั้งหลายโปรดระลึกถึงสิ่งนี้ไว้ด้วยหากท่านจะใช้หนังสือเล่มนี้เป็นข้ออ้างอิงในการโต้แย้งใด ๆ
diff --git a/book/chapter-10/README.md b/book/chapter-10/README.md
index e4a07eb..6618de8 100644
--- a/book/chapter-10/README.md
+++ b/book/chapter-10/README.md
@@ -1,8 +1,8 @@
-# Dependency injection
+# การส่งต่อ dependency (Dependency injection)
-Big part of the modules/components that we write have dependencies. A proper management of these dependencies is critical for the success of the project. There is a technique (most people consider it a *pattern*) called [*dependency injection*](http://krasimirtsonev.com/blog/article/Dependency-injection-in-JavaScript) that helps solving the problem.
+Components หรือ modules ที่ถูกเขียนขึ้นมาส่วนใหญ่มักจะมี dependencies ติดมาด้วยเสมอ การที่เราสามารถจัดการ dependencies เหล่านั้น จึงเป็นส่วนสำคัญที่ทำให้โปรเจคของเราสำเร็จลุล่วงไปด้วยดี ปัจจุบัน มีเทคนิคชนิดหนึ่ง (หรือที่หลาย ๆ คนเรียกว่า *pattern*) ที่สามารถช่วยจัดการ dependencies ของเราได้ นั้นก็คือ [*dependency injection*](http://krasimirtsonev.com/blog/article/Dependency-injection-in-JavaScript)
-In React the need of dependency injector is easily visible. Let's consider the following application tree:
+ใน React เราสามารถมองได้ง่าย ๆ ว่าส่วนไหนที่ต้องการ dependency injector (หรือ ส่วนที่ต้องการใช้ dependency) ยกตัวอย่างเช่น application tree ด้านล่าง
```js
// Title.jsx
@@ -35,9 +35,9 @@ class App extends React.Component {
};
```
-The string "React in patterns" should somehow reach the `Title` component. The direct way of doing this is to pass it from `App` to `Header` and then `Header` pass it down to `Title`. However, this may work for these three components but what happens if there are multiple properties and deeper nesting. Lots of components will act as proxy passing properties to their children.
+จากโค้ดตัวอย่าง จะเห็นได้ว่าค่าสตริง "React in patterns" จะต้องถูกส่งไปหา `Title` component โดยที่วิธีการตรง ๆ เลย คือการส่งค่าผ่าน props จาก `App` ไปยัง `Header` และจาก `Header` ไปยัง `Title` สำหรับ components สามตัวอาจจะไม่ใช้เรื่องแปลก แต่หาก components ที่เราต้องทำงานด้วยนั้น มี props ที่หลากหลาย และ มี component ที่ซ้อนกันหลาย ๆ ชั้น จะต้องมี components ระหว่างทางหลายตัวที่จะได้รับค่าไป เพียงเพื่อโยนไปให้ตัวลูกโดยที่ตัวเองไม่ได้ใช้
-We already saw how the [higher-order component](https://github.com/krasimir/react-in-patterns/tree/master/patterns/higher-order-components) may be used to inject data. Let's use the same technique to inject the `title` variable:
+จากที่ผ่านมา เราได้เห็นแล้วว่า [higher-order component](https://github.com/krasimir/react-in-patterns/tree/master/patterns/higher-order-components) นั้นสามารถใช้สำหรับการส่งค่าลงไปได้ เราจะมาลองใช้เทคนิคที่ว่ากับตัวแปร `title` ดู
```js
// inject.jsx
@@ -71,16 +71,16 @@ export default function Header() {
}
```
-The `title` is hidden in a middle layer (higher-order component) where we pass it as a prop to the original `Title` component. That's all nice but it solves only half of the problem. Now we don't have to pass the `title` down the tree but how this data reaches the `inject.jsx` helper.
+ตอนนี้ตัวแปร `title` ได้ถูกซ่อนอยู่ในเลเยอร์ตรงกลาง (higher-order component) จากตรงนั้นมันจะถูกส่งไปหา `Title` component ผ่าน props โดยตรง ท่านี้แก้ปัญหาได้ครึ่งทาง เราไม่ต้องกังวลเรื่องการส่ง `title` ลงไปหลาย ๆ ชั้นอีกแล้ว แต่ยังมีปัญหาเรื่องที่ว่า เราจะทำยังไงให้ค่าวิ่งไปหา `inject.jsx`
-## Using React's context (prior v. 16.3)
+## การใช้ React's context (เวอร์ชั่นก่อนหน้า 16.3)
-*In v16.3 React's team introduced a new version of the context API and if you are going to use that version or above you'd probably skip this section.*
+*ในเวอร์ชั่น 16.3, ทีมผู้พัฒนา React ได้ เสนอ context API ตัวใหม่ และ สำหรับคนที่คิดว่าจะใช้ เวอร์ชั่น 16.3 หรือ มากกว่า สามารถข้ามส่วนนี้ไปได้เลย*
-React has the concept of [*context*](https://facebook.github.io/react/docs/context.html). The *context* is something that every React component has access to. It's something like an [event bus](https://github.com/krasimir/EventBus) but for data. A single *store* which we access from everywhere.
+ในโลกของ React นั้น มีแนวคิดที่ชื่อว่า [*context*](https://facebook.github.io/react/docs/context.html) ซึ่ง context นั้นคือสิ่ง ๆ หนึ่งที่ React component ทุกตัวสามารถหยิบมาใช้ได้ แนวคิดของ context นั้นจะคล้าย ๆ กับ [event bus](https://github.com/krasimir/EventBus) สำหรับการส่งข้อมูล หรือ *store* อันหนึ่ง ที่สามารถเข้าถึงจากที่ไหนก็ได้
```js
-// a place where we will define the context
+// จุดที่เราทำการประกาศ context
var context = { title: 'React in patterns' };
class App extends React.Component {
@@ -93,7 +93,7 @@ App.childContextTypes = {
title: React.PropTypes.string
};
-// a place where we use the context
+// จุดที่เราจะใช้ context
class Inject extends React.Component {
render() {
var title = this.context.title;
@@ -105,7 +105,7 @@ Inject.contextTypes = {
};
```
-Notice that we have to specify the exact signature of the context object. With `childContextTypes` and `contextTypes`. If those are not specified then the `context` object will be empty. That may be a little bit frustrating because we may have lots of stuff to put there. That is why it is a good practice that our `context` is not just a plain object but it has an interface that allows us to store and retrieve data. For example:
+จะเห็นได้จากโค้ดด้านบน ว่าเราจะต้องประกาศ object context พร้อมตัวแปรที่เราจะใช้ ผ่าน `childContextTypes` และ `contextTypes` ถ้าเราไม่ประกาศ object `context` จะมาเป็น object เปล่า ๆ ซึ่งบางครั้งก็อาจจะทำให้รู้สึกหงุดหงิด ที่ต้องมานั่งใส่ตัวแปรหลาย ๆ ตัวลงไปในนั้น เพราะฉะนั้นวิธีการที่ดีคือ การเปลี่ยน `context` ให้มี interface ที่สามารถเก็บและส่งค่าได้ ดังตัวอย่างด้านล่าง
```js
// dependencies.js
@@ -119,7 +119,8 @@ export default {
}
}
```
-Then, if we go back to our example, the `App` component may look like that:
+
+ถ้านำกลับไปใช้กับตัวอย่างเดิม หน้าตาของ `App` component จะเป็นเหมือนด้านล่าง:
```js
import dependencies from './dependencies';
@@ -141,7 +142,7 @@ App.childContextTypes = {
};
```
-And our `Title` component gets it's data through the context:
+และ `Title` component ของเรา จะสามารถนำค่าจาก context ออกมาใช้ได้
```js
// Title.jsx
@@ -157,7 +158,8 @@ Title.contextTypes = {
};
```
-Ideally we don't want to specify the `contextTypes` every time when we need an access to the context. This detail may be wrapped again in a higher-order component. And even better, we may write an utility function that is more descriptive and helps us declare the exact wiring. I.e instead of accessing the context directly with `this.context.get('title')` we ask the higher-order component to get what we need and pass it as props to our component. For example:
+ตามหลักการแล้ว เราไม่อยากที่จะนั่งประกาศ `contextTypes` ในทุก ๆ ครั้งที่เราอยากจะเข้าถึง context ในส่วนนี้เราสามารถนำ higher-order component มาครอบได้ และที่ดีกว่าคือเราสามารถเขียน utility function ที่มีความหมายชัดเจนมากกว่า และ ช่วยให้เราสามารถต่อ context ได้อย่างถูกต้อง ยกตัวอย่าง เช่น แทนที่เราจะเข้าถึง context ตรง ๆ ผ่าน `this.context.get('title')` เราสามารถขอ context ผ่าน higher-order component และให้ higher-order component ส่งค่ามาในรูปแบบของ props แทน ดังตัวอย่างด้านล่าง:
+
```js
// Title.jsx
@@ -172,9 +174,10 @@ export default wire(Title, ['title'], function resolve(title) {
});
```
-The `wire` function accepts a React component, then an array with all the needed dependencies (which are `register`ed already) and then a function which I like to call `mapper`. It receives what is stored in the context as a raw data and returns an object which is later used as props for our component (`Title`). In this example we just pass what we get - a `title` string variable. However, in a real app this could be a collection of data stores, configuration or something else.
+ฟังก์ชัน `wire` รับ React component, array ที่ประกอบด้วย dependencies (ที่`เชื่อมต่อ`เข้ากับ context แล้ว) ที่เราต้องการจะเรียกใช้ และ ฟังก์ชันที่ผู้เขียนชอบเรียกว่า `mapper` ซึ่งฟังก์ชันนี้จะรับค่ามาจาก context และ return ค่าในรูปแบบของ object โดยที่ object นั้นท้ายที่สุดแล้วจะถูกส่งให้ component ของเรา (`Title`) ในรูปแบบของ props ดังที่เห็นในตัวอย่างนี้ เรานำตัวแปร `title` ส่งเข้าไป
+ในการเขียนแอปจริง ๆ ค่าที่ส่งเข้าไปอาจจะเป็น กลุ่มข้อมูลหลาย ๆ อัน, configuration หรือ อื่น ๆ
-Here is how the `wire` function looks like:
+และนี้คือหน้าตาของฟังก์ชัน `wire`:
```js
export default function wire(Component, dependencies, mapper) {
@@ -197,15 +200,15 @@ export default function wire(Component, dependencies, mapper) {
};
```
-`Inject` is a higher-order component that gets access to the context and retrieves all the items listed under `dependencies` array. The `mapper` is a function receiving the `context` data and transforms it to props for our component.
+`Inject` คือ higher-order component ที่สามารถเข้าถึง context และ นำค่าที่ประกาศไว้ใน array `dependencies` ออกมา ส่วนฟังก์ชัน `mapper` ทำหน้าที่รับ `context` เหล่านั้น และ ส่งเข้าไปหา component ของเราผ่าน props
-## Using React's context (v. 16.3 and above)
+## การใช้ React's context (เวอร์ชั่น 16.3 หรือ มากกว่า)
-For years the context API was not really recommended by Facebook. They mentioned in the official docs that the API is not stable and may change. And that is exactly what happened. In the version 16.3 we got a new one which I think is more natural and easy to work with.
+เป็นเวลาหลายปีที่ Facebook ไม่แนะนำให้ใช้ context API โดยให้เหตุผลไว้ใน official docs ว่า API นั้น ไม่เสถียร และ เสี่ยงต่อการเปลี่ยนแปลงในอนาคต และนั้นคือสิ่งที่เกิดขึ้นในปัจจุบัน ในเวอร์ชั่น 16.3 เราได้ API อันใหม่ ซึ่งผู้เขียนคิดว่า API นี้เป็นธรรมชาติมากขึ้น และ ใช้งานได้ง่ายกว่า
-Let's use the same example with the string that needs to reach a `
` component.
+สมมุติว่าเราลองนำตัวอย่างเดิมมาใช้ ตัวอย่างที่เราต้องการส่งสตริงไปหา `` component
-We will start by defining a file that will contain our context initialization:
+เราเริ่มโดยการสร้างไฟล์สำหรับการสร้าง context
```js
// context.js
@@ -217,9 +220,9 @@ export const Provider = Context.Provider;
export const Consumer = Context.Consumer;
```
-`createContext` returns an object that has `.Provider` and `.Consumer` properties. Those are actually valid React classes. The `Provider` accepts our context in the form of a `value` prop. The consumer is used to access the context and basically read data from it. And because they usually live in different files it is a good idea to create a single place for their initialization.
+ฟังก์ชัน `createContext` returns object ตัวหนึ่ง ที่มี properties ประกอบด้วย `.Provider` และ `.Consumer` โดยที่สองตัวนี้จริง ๆ แล้วคือ React class และสำหรับตัว Provider นั้น จะรับ context ผ่าน props ชื่อ `value` ในขณะที่ตัว consumer นั้น จะใช้สำหรับการเข้าถึงและอ่านค่า context ปกติแล้วสองตัวนี้จะอยู่คนละไฟล์ มันจึงเป็นความคิดที่ดี ที่จะสร้างที่ ๆ หนึ่งสำหรับการสร้างสองตัวนั้น
-Let's say that our `App` component is the root of our tree. At that place we have to pass the context.
+สมมุติว่า `App` component ของเรานั้นคือจุดสูงสุดของ application tree ข้างในนั้นเราจะทำการส่ง context เข้าไป
```js
import { Provider } from './context';
@@ -237,7 +240,7 @@ class App extends React.Component {
};
```
-The wrapped components and their children now share the same context. The `` component is the one that needs the `title` string so that is the place where we use the ``.
+ตอนนี้ components ที่โดยครอบและลูก ๆ ของมันได้ถูกแชร์ context อันเดียวกัน และ `` component คือตัวที่ต้องการสตริง `title` ตรงนี้จึงเป็นที่ ๆ เราจะนำ `` มาใช้
```js
import { Consumer } from './context';
@@ -251,23 +254,23 @@ function Title() {
}
```
-*Notice that the `Consumer` class uses the function as children (render prop) pattern to deliver the context.*
+*สังเกตุได้ว่า `Consumer` class ใช้ function as children (render prop) pattern สำหรับการส่ง context*
-The new API feels easier to understand and eliminates the boilerplate. It is still pretty new but looks promising. It opens a whole new range of possibilities.
+API อันใหม่นั้น ง่ายต่อการเข้าใจ ทั้งยังทำให้เราไม่ต้องใช้ boilerplate สำหรับตัว API นั้นค่อนข้างใหม่แต่ดูมีแนวโน้มที่ดี มันเปิดโอกาสให้เราเข้าถึงความเป็นไปได้ที่หลากหลายมากขึ้น
-## Using the module system
+## การใช้ module system
-If we don't want to use the context there are a couple of other ways to achieve the injection. They are not exactly React specific but worth mentioning. One of them is using the module system.
+ถ้าเราไม่ต้องการที่จะใช้ context ก็มีทางเลือกอื่นที่สามารถทำให้เราทำ injection ได้ โดยที่ทางเลือกนั้นอาจจะไม่เจาะจงไปที่ React แต่ก็ควรค่าแก่การกล่าวถึง หนึ่งในนั้นคือการใช้ module system
-As we know the typical module system in JavaScript has a caching mechanism. It's nicely noted in the [Node's documentation](https://nodejs.org/api/modules.html#modules_caching):
+อย่างที่รู้ ๆ กันว่า ปกติแล้ว module system ใน Javascript นั้นมีกลไกการทำ caching โดยได้มีการโน้ตไว้ใน [Node's documentation](https://nodejs.org/api/modules.html#modules_caching):
-> Modules are cached after the first time they are loaded. This means (among other things) that every call to require('foo') will get exactly the same object returned, if it would resolve to the same file.
+> Modules นั้นจะถูก cached หลังจากที่มันถูกโหลดขึ้นมาครั้งแรก นั้นหมายความว่า ทุกครั้งที่เราเรียก required('foo') object อันเดิมจะถูกนำมาใช้เสมอถ้ามัน resolve ไปหาไฟล์อันเดิม
-> Multiple calls to require('foo') may not cause the module code to be executed multiple times. This is an important feature. With it, "partially done" objects can be returned, thus allowing transitive dependencies to be loaded even when they would cause cycles.
+> การเรียกไปหา require('foo') หลาย ๆ ครั้ง จะไม่ทำให้โค้ดข้างใน foo module ถูกเรียกใหม่ซ้ำ ๆ นี้เป็นฟีเจอร์ที่สำคัญมากเพราะว่า "partially done" object (object ที่ยังรันไม่เสร็จ แต่ถูก require) จะถูก return ออกมาได้ และ ทำให้ transitive dependencies (dependency ตอนที่ modules require กันเอง) ถูกโหลดโดยไม่ทำให้เกิดลูป (cyclic dependency)
-How is that helping for our injection? Well, if we export an object we are actually exporting a [singleton](https://addyosmani.com/resources/essentialjsdesignpatterns/book/#singletonpatternjavascript) and every other module that imports the file will get the same object. This allows us to `register` our dependencies and later `fetch` them in another file.
+แล้วสิ่งเหล่านี้จะช่วยเราในการทำ injection อย่างไร ? มันช่วยเราได้เพราะ object ที่ถูก export ออกมานั้น จริง ๆ แล้วคือ [singleton](https://addyosmani.com/resources/essentialjsdesignpatterns/book/#singletonpatternjavascript) และทุก module ที่ import ไฟล์นั้นเข้าไป ก็จะเข้าถึงอ็อบเจกต์ตัวเดียวกัน นั้นทำให้เราสามารถ ใส่ dependencies ของเราลงไป (`register`) และ นำออกมาจากไฟล์อื่น ๆ ได้ (`fetch`)
-Let's create a new file called `di.jsx` with the following content:
+เราลองมาสร้างไฟล์ใหม่ชื่อ `di.jsx` ที่มีคอนเทนต์ตามด้านล่าง:
```js
var dependencies = {};
@@ -300,9 +303,9 @@ export function wire(Component, deps, mapper) {
}
```
-We'll store the dependencies in `dependencies` global variable (it's global for our module, not for the whole application). We then export two functions `register` and `fetch` that write and read entries. It looks a little bit like implementing setter and getter against a simple JavaScript object. Then we have the `wire` function that accepts our React component and returns a [higher-order component](https://github.com/krasimir/react-in-patterns/tree/master/patterns/higher-order-components). In the constructor of that component we are resolving the dependencies and later while rendering the original component we pass them as props. We follow the same pattern where we describe what we need (`deps` argument) and extract the needed props with a `mapper` function.
+เราะจะเก็บ dependecies ไว้ในตัวแปร global ชื่อ `dependencies` (ตัวแปร global ในระดับ module ไม่ใช้ระดับแอปพลิเคชัน) หลังจากนั้นเราจะ export สองฟังก์ชันได้แก่ `register` และ `fetch` ที่จะทำหน้าที่เขียนและอ่านค่าต่าง ๆ โดยที่มันจะคล้าย ๆ กับการสร้าง setter และ getter ใน object ของ Javascript ต่อจากนั้นเราจะใช้ฟังก์ชัน `wire` ในการรับ React component และ return [higher-order component](https://github.com/krasimir/react-in-patterns/tree/master/patterns/higher-order-components) ออกไป และใน constructor ของ component ที่อยู่ข้างในฟังก์ชัน wire เราจะทำการดึง dependencies ออกมา แล้วก็ส่งมันลงไปหา component ข้างใต้ที่กำลัง render ในรูปแบบของ props โดยที่เราจะทำตาม pattern เดิมที่เราอธิบายสิ่งที่เราต้องการ (`deps` argument) และดึง props ที่ต้องการออกมาผ่านฟังก์ชัน `mapper`
-Having the `di.jsx` helper we are again able to register our dependencies at the entry point of our application (`app.jsx`) and inject them wherever (`Title.jsx`) we need.
+การที่เรามี `di.jsx` helper นั้นทำให้เราสามารถสร้าง dependencies ได้ที่จุดเริ่มต้นของแอปพลิเคชัน (`app.jsx`) และ ส่งมันลงไปในที่ ๆ เราต้องการได้ (`Title.jsx`)
@@ -346,8 +349,8 @@ export default wire(
);
```
-*If we look at the `Title.jsx` file we'll see that the actual component and the wiring may live in different files. That way the component and the mapper function become easily unit testable.*
+*ถ้าเรามองที่ไฟล์ `Title.jsx` เราจะเห็นว่าตัว component และ ส่วนที่ทำการเชื่อมต่อนั้นสามารถอยู่คนละไฟล์ได้ ซึ่งท่านี้จะทำให้ตัว component และฟังก์ชัน mapper นั้นง่ายต่อการทำ unit test*
-## Final thoughts
+## ข้อคิด
-Dependency injection is a tough problem. Especially in JavaScript. Lots of people didn't realize that but putting a proper dependency management is a key process of every development cycle. JavaScript ecosystem offers different tools and we as developers should pick the one that fits in our needs.
+Dependency injection นั้นเป็นปัญหาที่ยากโดยเฉพาะใน Javascript หลาย ๆ คนไม่คำนึงถึงว่าการทำ dependency management ที่เหมาะสมนั้น เป็นกระบวนการสำคัญในทุก development cycle และในส่วนของ JavaScript ecosystem นั้น มี tools ที่หลากหลายมานำเสนอให้เราอยู่เสมอ และ เรา developers ควรที่จะเลือกหยิบสิ่งที่ตอบโจทย์ต่อความต้องการของเรามากที่สุด
diff --git a/book/chapter-11/README.md b/book/chapter-11/README.md
index c7b9da2..4169467 100644
--- a/book/chapter-11/README.md
+++ b/book/chapter-11/README.md
@@ -1,10 +1,10 @@
-# Styling React components
+# การตกแต่ง React components
-React is a view layer. As such it kind of controls the markup rendered in the browser. And we know that the styling with CSS is tightly connected to the markup on the page. There are couple of approaches for styling React applications and in this section we will go through the most popular ones.
+React นั้นเป็นส่วนแสดงผล ซึ่งเป็นการควมคุม Markup ที่จะแสดงผลในเบราว์เซอร์ เรามักจะใช้ CSS ในการตกแต่งหน้า Markup ของเรา มีหลายวิธีมากในการจัดการกับ Styling บนแอพพลิเคชั่น React และในบทนี้ เราจะมาพูดถึงวิธีการที่นิยมกัน
-## The good old CSS class
+## CSS Class ที่ดีในทุกยุคสมัย
-JSX syntax is pretty close to HTML syntax. As such we have almost the same tag attributes and we may still style using CSS classes. Classes which are defined in an external `.css` file. The only caveat is using `className` and not `class`. For example:
+JSX Syntax นั้นมีความใกล้เคียงกับภาษา HTML ซึ่งนั่นก็คือเรายังคงใช้ Attribute ต่าง ๆ เหมือนกัน และเราอาจจะยังคงใช้ CSS Class ในการ Styling โดยที่ Class ต่างๆ ถูกประกาศจากไฟล์ `.css` โดยมีข้อแตกต่างอย่างนึงก็คือต้องใช้ `className` ไม่ใช่ `class` เช่น
```
Styling
@@ -12,7 +12,7 @@ JSX syntax is pretty close to HTML syntax. As such we have almost the same tag a
## Inline styling
-The inline styling works just fine. Similarly to HTML we are free to pass styles directly via a `style` attribute. However, while in HTML the value is a string in JSX must be an object.
+การทำ Inline CSS ก็สามารถทำได้ดีเช่นเดียวกับ HTML ที่เราสามารถส่งค่า Parameter ต่าง ๆ ได้โดยตรงผ่าน Attribute `style` แต่อย่างไรก็ตาม ใน JSX นั้นเราจะต้องกำหนด Styling ด้วย Object แตกต่างจาก HTML ที่กำหนดเป็น String
```js
const inlineStyles = {
@@ -25,7 +25,8 @@ const inlineStyles = {
Inline styling
```
-Because we write the styles in JavaScript we have some limitations from a syntax point of view. If we want to keep the original CSS property names we have to put them in quotes. If not then we have to follow the camel case convention. However, writing styles in JavaScript is quite interesting and may be a lot more flexible then the plain CSS. Like for example inheriting of styles:
+เพราะว่าเราเขียน Style ใน Syntax ของ JavaScript เราจึงมีข้อจำกัดของ Syntax
+หากเราต้องการเขียน CSS Property ในแบบของ CSS ดั้งเดิมนั้น เราจะต้องเขียนภายใน Quote ( เครื่องหมาย ", ' ) ถ้าไม่เช่นนั้นคุณก็จะต้องเขียนตามหลัก Camel Case อย่างไรก็ตาม Styling ใน JavaScript นั้นมีความน่าสนใจและยืดหยุ่นได้หลากหลายวิธีกว่า CSS ปกติทั่วไป (เช่น Plain CSS ใน HTML) ดังในตัวอย่างด้านล่างนี้ เราส่งผ่าน Property จาก Style หนึ่งไปยังอีก Style หนึ่ง:
```js
const theme = {
@@ -33,20 +34,20 @@ const theme = {
color: 'blue'
};
const paragraphText = {
+ // ES2018 object spread
...theme,
fontSize: '20px'
};
```
-We have some basic styles in `theme` and with mix them with what is in `paragraphText`. Shortly, we are able to use the whole power of JavaScript to organize our CSS. What it matters at the end is that we generate an object that goes to the `style` attribute.
+เรามี Style ชุดนึงใน `theme` และเราก็เรียกใช้มันภายใน Style ของ `paragraphText` อธิบายง่าย ๆ ก็คือ เราสามารถใช้ความสามารถของ JavaScript ในการจัดการ CSS ของเรา สิ่งที่เราต้องการให้คุณเห็นคือสุดท้ายเราได้สร้าง Object หนึ่ง ซึ่งมันจะไปแทรกตัวอยู่ใน Attribute `style`
## CSS modules
-[CSS modules](https://github.com/css-modules/css-modules/blob/master/docs/get-started.md) is building on top of what we said so far. If we don't like the JavaScript syntax then we may use CSS modules and we will be able to write plain CSS. Usually this library plays its role at bundling time. It is possible to hook it as part of the transpilation step but normally is distributed as a build system plugin.
+[CSS modules](https://github.com/css-modules/css-modules/blob/master/docs/get-started.md) นั้นสร้างขึ้นจากแนวคิดของสิ่งที่เราได้กล่าวไปก่อนหน้านี้ ถ้าเราไม่ชอบการเขียน CSS ภายใต้ Syntax ของ JavaScript เราสามารถใช้ CSS Module ที่ทำให้เราสามารถเขียน CSS ในรูปแบบและ Syntax ของ CSS ได้ ( ดังที่กล่าวไปว่าการเขียน CSS โดยที่ไม่มี CSS module นั้นจะต้องเขียนใน Syntax ของ JavaScript )
+ปกติแล้ว Library นี้จะจัดการงานของมันในช่วง Building Time มันเป็นไปได้ที่เราจะเข้าใจว่ามันคือส่วนหนึ่งของกระบวนการ [Transpilation](https://scotch.io/tutorials/javaScript-transpilers-what-they-are-why-we-need-them) แต่โดยปกติแล้วมันก็คือ build system plug-in ชนิดหนึ่ง
-Here is a quick example to get an idea how it works:
-
-