Skip to content

Commit 0565c78

Browse files
authored
docs: Advanced Guides > Reactivity Fundamentals の翻訳 (#31) (#82)
* docs: translate guide/reactivity-fundamentals.md (#31) * fix translate (#31)
1 parent bde755b commit 0565c78

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/guide/reactivity-fundamentals.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
# Reactivity Fundamentals
1+
# リアクティブの基礎
22

3-
## Declaring Reactive State
3+
## リアクティブな状態の宣言
44

5-
To create a reactive state from a JavaScript object, we can use a `reactive` method:
5+
JavaScript のオブジェクトからリアクティブな状態を作る目的で、`reactive` メソッドを用いることができます:
66

77
```js
88
import { reactive } from 'vue'
99

10-
// reactive state
10+
// リアクティブな状態
1111
const state = reactive({
1212
count: 0
1313
})
1414
```
1515

16-
`reactive` is the equivalent of the `Vue.observable()` API in Vue 2.x, renamed to avoid confusion with RxJS observables. Here, the returned state is a reactive object. The reactive conversion is "deep" - it affects all nested properties of the passed object.
16+
`reactive` は Vue 2.x における `Vue.observable()` API に相当し、RxJS における observables との混同を避けるために改名されました。ここで、返される状態はリアクティブオブジェクトです。リアクティブの変換は "deep" であり、渡されたオブジェクトのすべての入れ子になっているプロパティに影響を与えます。
1717

18-
The essential use case for reactive state in Vue is that we can use it during render. Thanks to dependency tracking, the view automatically updates when reactive state changes.
18+
Vue におけるリアクティブな状態の重要なユースケースは描画の際に用いることができることです。依存関係の追跡のおかげで、リアクティブな状態が変化するとビューが自動的に更新されます。
1919

20-
This is the very essence of Vue's reactivity system. When you return an object from `data()` in a component, it is internally made reactive by `reactive()`. The template is compiled into a [render function](render-function.html) that makes use of these reactive properties.
20+
これがまさに Vue のリアクティブシステムの本質です。コンポーネント内の `data()` でオブジェクトを返す際に、内部的には `reactive()` によってリアクティブを実現しています。テンプレートはこれらのリアクティブなプロパティを利用する [render 関数](render-function.html)にコンパイルされます。
2121

22-
You can learn more about `reactive` in the [Basic Reactivity API's](../api/basic-reactivity.html) section
22+
`reactive` についての詳細は [基本 リアクティビティ API](../api/basic-reactivity.html) セクションを参照してください
2323

24-
## Creating Standalone Reactive Values as `refs`
24+
## 独立したリアクティブな値を `参照` として作成する
2525

26-
Imagine the case where we have a standalone primitive value (for example, a string) and we want to make it reactive. Of course, we could make an object with a single property equal to our string, and pass it to `reactive`. Vue has a method that will do the same for us - it's a `ref`:
26+
独立したプリミティブ値(例えば文字列)があって、それをリアクティブにしたい場合を想像してみてください。もちろん、同じ値の文字列を単一のプロパティとして持つオブジェクトを作成して `reactive` に渡すこともできます。Vue にはこれと同じことをしてくれる `ref` メソッドがあります:
2727

2828
```js
2929
import { ref } from 'vue'
3030

3131
const count = ref(0)
3232
```
3333

34-
`ref` will return a reactive and mutable object that serves as a reactive **ref**erence to the internal value it is holding - that's where the name comes from. This object contains the only one property named `value`:
34+
`ref` は、オブジェクト内部の値をリアクティブな参照(**ref**erence - メソッド名の由来)として機能させるミュータブルオブジェクトを返します。このオブジェクトには `value` という名前のプロパティが1つだけ含まれています:
3535

3636
```js
3737
import { ref } from 'vue'
@@ -43,9 +43,9 @@ count.value++
4343
console.log(count.value) // 1
4444
```
4545

46-
### Ref Unwrapping
46+
### ref のアンラップ
4747

48-
When a ref is returned as a property on the render context (the object returned from [setup()](composition-api-setup.html)) and accessed in the template, it automatically unwraps to the inner value. There is no need to append `.value` in the template:
48+
ref がレンダーコンテキスト(render contenxt - [setup()](composition-api-setup.html) によって返されるオブジェクト)のプロパティとして返されていてテンプレート内でアクセスされる場合、自動的に内部の値にアンラップ(ref でラップされた値を取り出す)されます。テンプレート内においては `.value` を付ける必要はありません:
4949

5050
```vue-html
5151
<template>
@@ -68,9 +68,9 @@ When a ref is returned as a property on the render context (the object returned
6868
</script>
6969
```
7070

71-
### Access in Reactive Objects
71+
### リアクティブオブジェクト内でのアクセス
7272

73-
When a `ref` is accessed or mutated as a property of a reactive object, it automatically unwraps to the inner value so it behaves like a normal property:
73+
`ref` がリアクティブオブジェクトのプロパティとしてアクセスまたは更新される際に、自動的に内部の値にアンラップされて通常のプロパティのように振る舞います:
7474

7575
```js
7676
const count = ref(0)
@@ -84,7 +84,7 @@ state.count = 1
8484
console.log(count.value) // 1
8585
```
8686

87-
If a new ref is assigned to a property linked to an existing ref, it will replace the old ref:
87+
既に ref とリンクしているプロパティに新しい ref が割り当てられた場合、古い ref に取って代わることになります:
8888

8989
```js
9090
const otherCount = ref(2)
@@ -94,21 +94,21 @@ console.log(state.count) // 2
9494
console.log(count.value) // 1
9595
```
9696

97-
Ref unwrapping only happens when nested inside a reactive `Object`. There is no unwrapping performed when the ref is accessed from an `Array` or a native collection type like [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map):
97+
ref のアンラップはリアクティブな `Object` の中の入れ子となっている場合にのみ発生します。ref `Array` [`Map`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Map) のようなネイティブのコレクション型からアクセスされた場合、アンラップは行われません:
9898

9999
```js
100100
const books = reactive([ref('Vue 3 Guide')])
101-
// need .value here
101+
// ここでは .value が必要です
102102
console.log(books[0].value)
103103

104104
const map = reactive(new Map([['count', ref(0)]]))
105-
// need .value here
105+
// ここでは .value が必要です
106106
console.log(map.get('count').value)
107107
```
108108

109-
## Destructuring Reactive State
109+
## リアクティブな状態の分割代入
110110

111-
When we want to use a few properties of the large reactive object, it could be tempting to use [ES6 destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) to get properties we want:
111+
大きなリアクティブオブジェクトのプロパティをいくつかを使いたいときに、[ES6 の分割代入](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)を使ってプロパティを取得したくなることがあります:
112112

113113
```js
114114
import { reactive } from 'vue'
@@ -124,7 +124,7 @@ const book = reactive({
124124
let { author, title } = book
125125
```
126126

127-
Unfortunately, with such a destructuring the reactivity for both properties would be lost. For such a case, we need to convert our reactive object to a set of refs. These refs will retain the reactive connection to the source object:
127+
残念ながら、このような分割代入をすることで両方のプロパティのリアクティブが失われてしまいます。このような場合においてはリアクティブオブジェクトを ref のセットに変換する必要があります。これらの ref は元となるオブジェクトへのリアクティブな接続を保持します:
128128

129129
```js
130130
import { reactive, toRefs } from 'vue'
@@ -139,15 +139,15 @@ const book = reactive({
139139

140140
let { author, title } = toRefs(book)
141141

142-
title.value = 'Vue 3 Detailed Guide' // we need to use .value as title is a ref now
142+
title.value = 'Vue 3 Detailed Guide' // ここで title は ref であるため .value を用いる必要があります
143143
console.log(book.title) // 'Vue 3 Detailed Guide'
144144
```
145145

146-
You can learn more about `refs` in the [Refs API](../api/refs-api.html#ref) section
146+
`ref` で作成した `参照` についての詳細は [参照 (refs) API](../api/refs-api.html#ref) セクションを参照してください
147147

148-
## Prevent Mutating Reactive Objects with `readonly`
148+
## `readonly` でリアクティブオブジェクトの変更を防ぐ
149149

150-
Sometimes we want to track changes of the reactive object (`ref` or `reactive`) but we also want prevent changing it from a certain place of the application. For example, when we have a [provided](component-provide-inject.html) reactive object, we want to prevent mutating it where it's injected. To do so, we can create a readonly proxy to the original object:
150+
リアクティブオブジェクト(`ref` `reactive`)の変更を追跡しながらも、アプリケーションのある場所からの変更は防ぎたい場合があります。例えば、[provide](component-provide-inject.html) されたリアクティブオブジェクトがある場合、それが注入された場所からの変更は防ぎたいことがあります。そうするために、元のオブジェクトに対する読み取り専用のプロキシを作成します:
151151

152152
```js
153153
import { reactive, readonly } from 'vue'
@@ -156,9 +156,9 @@ const original = reactive({ count: 0 })
156156

157157
const copy = readonly(original)
158158

159-
// mutating original will trigger watchers relying on the copy
159+
// original を変更すると copy 側の依存ウォッチャが発動します
160160
original.count++
161161

162-
// mutating the copy will fail and result in a warning
162+
// copy を変更しようとすると失敗し、警告が表示されます
163163
copy.count++ // warning: "Set operation on key 'count' failed: target is readonly."
164164
```

0 commit comments

Comments
 (0)