Skip to content

Commit 483f7e8

Browse files
toshilowkazupon
authored andcommitted
Reactivity in depth (vuejs#178)
* translate reactivity * Fix little wrong translation * update words by review comment
1 parent 531354b commit 483f7e8

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/guide/reactivity.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
11
---
2-
title: Reactivity in Depth
2+
title: リアクティブの探求
33
type: guide
44
order: 15
55
---
66

7-
We've covered most of the basics - now it's time to take a deep dive! One of Vue's most distinct features is the unobtrusive reactivity system. Models are just plain JavaScript objects. When you modify them, the view updates. It makes state management very simple and intuitive, but it's also important to understand how it works to avoid some common gotchas. In this section, we are going to dig into some of the lower-level details of Vue's reactivity system.
7+
私達は基本のほとんどをカバーしてきました。 - これからは深いダイビングをするための時間です! Vueの最も明確な特徴の1つは、控えめなリアクティブシステムです。モデルは単なるプレーンな JavaScript オブジェクトです。それらを変更する時、View を更新します。状態管理を非常にシンプルかつ直感的にしますが、いくつかの一般的な落とし穴を避けるためにそれがどのように動作するか理解することも重要です。このセクションで、私達は Vue のリアクティブシステムの低レベルの詳細の一部について掘り下げていきます。
88

9-
## How Changes Are Tracked
9+
## 変更の追跡方法
1010

11-
When you pass a plain JavaScript object to a Vue instance as its `data` option, Vue will walk through all of its properties and convert them to getter/setters using [Object.defineProperty](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty). This is an ES5-only and un-shimmable feature, which is why Vue doesn't support IE8 and below.
11+
プレーンな JavaScript オブジェクトを `data` オプションとして Vue インスタンスに渡すとき、Vue.js はその全てのプロパティを渡り歩いて、それらを [Object.defineProperty](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) を使用して、getter/setter に変換します。これは ES5 だけのシム (shim) ができない機能で、Vue.js が IE8 以下をサポートしない理由です。
1212

13-
The getter/setters are invisible to the user, but under the hood they enable Vue to perform dependency-tracking and change-notification when properties are accessed or modified. One caveat is that browser consoles format getter/setters differently when converted data objects are logged, so you may want to install [vue-devtools](https://github.com/vuejs/vue-devtools) for a more inspection-friendly interface.
13+
getter/setter はユーザーには見えませんが、内部ではそれらは Vue.js で依存関係の追跡を実行したり、プロパティがアクセスされたまたは変更されたときは、変更通知します。注意事項の1つは、データオブジェクトが記録されたとき、getter/setter のブラウザコンソールのフォーマットが異なるので、よりフレンドリな閲覧インターフェイスのため、[vue-devtools](https://github.com/vuejs/vue-devtools) をインストールするといいでしょう。
1414

15-
Every component instance has a corresponding **watcher** instance, which records any properties "touched" during the component's render as dependencies. Later on when a dependency's setter is triggered, it notifies the watcher, which in turn causes the component to re-render.
15+
全てのコンポーネントインターフェイスは対応している **ウオッチャ (watcher)** インターフェイスを持っていて、そのインターフェイスは "触れた (touched)" 全てのプロパティをコンポーネントの依存関係としてレンダリングされている間、記録します。その後、依存する setter がトリガされる時、ウォッチャに通知され、コンポーネントが再描画する結果につながります。
1616

1717
![Reactivity Cycle](/images/data.png)
1818

19-
## Change Detection Caveats
19+
## 変更検出の注意事項
2020

21-
Due to the limitations of modern JavaScript (and the abandonment of `Object.observe`), Vue **cannot detect property addition or deletion**. Since Vue performs the getter/setter conversion process during instance initialization, a property must be present in the `data` object in order for Vue to convert it and make it reactive. For example:
21+
モダンな JavaScript の制限(そして `Object.observe` の放棄)のため、Vue.js は**プロパティの追加または削除を検出できません**。Vue.js はインスタンスの初期化中に、getter/setter 変換処理を実行するため、プロパティは、Vue がそれを変換しそしてそれをリアクティブにするために、`data` オブジェクトに存在しなければなりません。例えば:
2222

2323
``` js
2424
var vm = new Vue({
2525
data: {
2626
a: 1
2727
}
2828
})
29-
// `vm.a` is now reactive
29+
// `vm.a` は今リアクティブです
3030

3131
vm.b = 2
32-
// `vm.b` is NOT reactive
32+
// `vm.b` はリアクティブでは"ありません"
3333
```
3434

35-
Vue does not allow dynamically adding new root-level reactive properties to an already created instance. However, it's possible to add reactive properties to a nested object using the `Vue.set(object, key, value)` method:
35+
Vue はすでに作成されたインスタンスに対して動的に新しいルートレベルのリアクティブなプロパティを追加することはできません。しかしながら `Vue.set(object, key, value)` メソッドを使うことで、ネストしたオブジェクトにリアクティブなプロパティを追加することができます:
3636

3737
``` js
3838
Vue.set(vm.someObject, 'b', 2)
3939
```
4040

41-
You can also use the `vm.$set` instance method, which is just an alias to the global `Vue.set`:
41+
グローバル `Vue.set` の単なるエイリアスである `vm.$set` インスタンスメソッドを使用することもできます:
4242

4343
``` js
4444
this.$set(this.someObject, 'b', 2)
4545
```
4646

47-
Sometimes you may want to assign a number of properties to an existing object, for example using `Object.assign()` or `_.extend()`. However, new properties added to the object will not trigger changes. In such cases, create a fresh object with properties from both the original object and the mixin object:
47+
時どき、既存のオブジェクトにプロパティの数を割り当てたいということがあるかもしれません。例えば、`Object.assign()` または `_.extend()` を使用しながら。しかしながら、新しいプロパティをオブジェクトに追加したとき、トリガーは変更しません。このような場合、元のオブジェクトとミックスインオブジェクトの両方のプロパティを持つ新たなオブジェクトを作成します:
4848

4949
``` js
50-
// instead of `Object.assign(this.someObject, { a: 1, b: 2 })`
50+
// `Object.assign(this.someObject, { a: 1, b: 2 })` の代わり
5151
this.someObject = Object.assign({}, this.someObject, { a: 1, b: 2 })
5252
```
5353

54-
There are also a few array-related caveats, which were discussed earlier in the [list rendering section](/guide/list.html#Caveats).
54+
[以前に リストレンダリング のセクションで議論した](/guide/list.html#注意事項) いくつかの配列に関連した注意事項があります。
5555

56-
## Declaring Reactive Properties
56+
## リアクティブプロパティの宣言
5757

58-
Since Vue doesn't allow dynamically adding root-level reactive properties, this means you have to initialize you instances by declaring all root-level reactive data properties upfront, even just with an empty value:
58+
Vue は動的に新しいルートレベルのリアクティブなプロパティを追加することはできませので、前もってインスタンス全てのルートレベルのリアクティブな data を宣言して初期化する必要があります、空の値でもかまいません:
5959

6060
``` js
6161
var vm = new Vue({
6262
data: {
63-
// declare message with an empty value
63+
// 空の値として message を宣言する
6464
message: ''
6565
},
6666
template: '<div>{{ message }}</div>'
6767
})
68-
// set `message` later
68+
// 後で、`message` を追加する
6969
vm.message = 'Hello!'
7070
```
7171

72-
If you don't declare `message` in the data option, Vue will warn you that the render function is trying to access a property that doesn't exist.
72+
data オプションで `message` を宣言していないと、Vue render ファンクションが存在しないプロパティにアクセスしようとしていることを警告します。
7373

74-
There are technical reasons behind this restriction - it eliminates a class of edge cases in the dependency tracking system, and also makes Vue instances play nicer with type checking systems. But there is also an important consideration in terms of code maintainability: the `data` object is like the schema for your component's state. Declaring all reactive properties upfront makes the component code easier to understand when revisited later or read by another developer.
74+
この制限の背後には技術的な理由があります - それは依存性追跡システムにおけるエッジケースのクラスを排除し、 また Vue インスタンスと型チェックシステムとの親和性を高めます。しかし重要な考慮事項はコードの保守性にあります: `data` オブジェクトはコンポーネント状態のスキーマのようなものです。前もって全てのリアクティブなプロパティを宣言することで、後から見直したり別の開発者が読んだりしたときにコンポーネントのコードを簡単に理解することができます。
7575

76-
## Async Update Queue
76+
## 非同期更新キュー
7777

78-
In case you haven't noticed yet, Vue performs DOM updates **asynchronously**. Whenever a data change is observed, it will open a queue and buffer all the data changes that happen in the same event loop. If the same watcher is triggered multiple times, it will be pushed into the queue only once. This buffered de-duplication is important in avoiding unnecessary calculations and DOM manipulations. Then, in the next event loop "tick", Vue flushes the queue and performs the actual (already de-duped) work. Internally Vue uses `MutationObserver` if available for the asynchronous queuing and falls back to `setTimeout(fn, 0)`.
78+
もしあなたがまだ気づいていない場合、Vue **非同期** に DOM 更新を実行します。データ変更が監視されている限り、Vue はキューをオープンし、同じイベントループで起こる全てのデータ変更をバッファリングします。同じウオッチャが複数回トリガされる場合、一度だけキューに押し込まれます。この重複除外バッファリングは不要な計算や DOM 操作を回避する上で重要です。そして、次のイベントループの "tick" で、Vue はキューをフラッシュし、実際の(すでに重複が除外された)作業を実行します。内部的には、Vue はもし非同期キューイング向けに `MutationObserver` が利用可能ならそれを使い、`setTimeout(fn, 0)` にフォールバックします。
7979

80-
For example, when you set `vm.someData = 'new value'`, the component will not re-render immediately. It will update in the next "tick", when the queue is flushed. Most of the time we don't need to care about this, but it can be tricky when you want to do something that depends on the post-update DOM state. Although Vue.js generally encourages developers to think in a "data-driven" fashion and avoid touching the DOM directly, sometimes it might be necessary to get your hands dirty. In order to wait until Vue.js has finished updating the DOM after a data change, you can use `Vue.nextTick(callback)` immediately after the data is changed. The callback will be called after the DOM has been updated. For example:
80+
例として、`vm.someData = 'new value'` をセットした時、そのコンポーネントはすぐに再描画しません。 キューがフラッシュされた時、次の "tick" で更新します。ほとんどの場合、私達はこれについて気にする必要はありませんが、更新した DOM の状態に依存する何かをしたい時、注意が必要です。Vue.js は一般的に"データ駆動"的な流儀で考えることを開発者に奨励していますが、時どき、それはあなたの手を汚す必要があるかもしれません。Vue.js でデータの変更後に、DOM の更新が完了するまでに待つためには、データが変更された直後に `Vue.nextTick(callback)` を使用することができます。コールバックが呼ばれた時、DOM は更新されているでしょう。例えば:
8181

8282
``` html
8383
<div id="example">{{ message }}</div>
@@ -90,14 +90,14 @@ var vm = new Vue({
9090
message: '123'
9191
}
9292
})
93-
vm.message = 'new message' // change data
93+
vm.message = 'new message' // データを変更する
9494
vm.$el.textContent === 'new message' // false
9595
Vue.nextTick(function () {
9696
vm.$el.textContent === 'new message' // true
9797
})
9898
```
9999

100-
There is also the `vm.$nextTick()` instance method, which is especially handy inside components, because it doesn't need global `Vue` and its callback's `this` context will be automatically bound to the current Vue instance:
100+
特に便利な内部コンポーネントのインスタンスメソッド `vm.$nextTick()` もあります。なぜなら、それはグローバルな `Vue` とそのコールバックの `this` コンテキストは自動的に現在の Vue インスタンスにバウンドされるからです:
101101

102102
``` js
103103
Vue.component('example', {

0 commit comments

Comments
 (0)