Skip to content

Commit c90ee39

Browse files
committed
コード内のコメントを日本語に翻訳した
1 parent 5486068 commit c90ee39

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

ja/data.md

+28-30
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ SSR をしているとき、基本的にはアプリケーションの「スナ
1515
import Vue from 'vue'
1616
import Vuex from 'vuex'
1717
Vue.use(Vuex)
18-
// Assume we have a universal API that returns Promises
19-
// and ignore the implementation details
18+
// Promise を返すユニバーサルなアプリケーションを想定しています
19+
// また、実装の詳細は割愛します
2020
import { fetchItem } from './api'
2121
export function createStore () {
2222
return new Vuex.Store({
@@ -25,8 +25,8 @@ export function createStore () {
2525
},
2626
actions: {
2727
fetchItem ({ commit }, id) {
28-
// return the Promise via store.dispatch() so that we know
29-
// when the data has been fetched
28+
// store.dispatch() を使って Promise を返します
29+
// そうすればデータがフェッチされたときにそれを知ることができます
3030
return fetchItem(id).then(item => {
3131
commit('setItem', { id, item })
3232
})
@@ -51,27 +51,27 @@ import { createRouter } from './router'
5151
import { createStore } from './store'
5252
import { sync } from 'vuex-router-sync'
5353
export function createApp () {
54-
// create router and store instances
54+
// ルーターとストアのインスタンスを作成します
5555
const router = createRouter()
5656
const store = createStore()
57-
// sync so that route state is available as part of the store
57+
// ルートのステートをストアの一部として利用できるよう同期します
5858
sync(store, router)
59-
// create the app instance, injecting both the router and the store
59+
// アプリケーションのインスタンスを作成し、ルーターとストアの両方を挿入します
6060
const app = new Vue({
6161
router,
6262
store,
6363
render: h => h(App)
6464
})
65-
// expose the app, the router and the store.
65+
// アプリケーション、ルーター、ストアを露出します
6666
return { app, router, store }
6767
}
6868
```
6969

7070
## ロジックとコンポーネントとの結び付き
7171

72-
ではデータをプリフェッチするアクションをディスパッチするコードはどこに書けばよいでしょうか
72+
ではデータをプリフェッチするアクションをディスパッチするコードはどこに置けばよいでしょうか
7373

74-
フェッチする必要があるデータはアクセスしたルートによって決まります。またそのルートによってどのコンポーネントがレンダリングされるかも決まります。実のところ、与えられたルートに必要とされるデータは、そのルートでレンダリングされるコンポーネントに必要とされるデータでもあるのです。したがって、データをフェッチするロジックはルートコンポーネントの中に書くのが自然でしょう
74+
フェッチする必要があるデータはアクセスしたルートによって決まります。またそのルートによってどのコンポーネントがレンダリングされるかも決まります。実のところ、与えられたルートに必要とされるデータは、そのルートでレンダリングされるコンポーネントに必要とされるデータでもあるのです。したがって、データをフェッチするロジックはルートコンポーネントの中に置くのが自然でしょう
7575

7676
ルートコンポーネントではカスタム静的関数 `asyncData` が利用可能です。この関数はそのルートコンポーネントがインスタンス化される前に呼び出されるため `this` にアクセスできないことを覚えておいてください。ストアとルートの情報は引数として渡される必要があります:
7777

@@ -83,11 +83,11 @@ export function createApp () {
8383
<script>
8484
export default {
8585
asyncData ({ store, route }) {
86-
// return the Promise from the action
86+
// アクションから Promise が返されます
8787
return store.dispatch('fetchItem', route.params.id)
8888
},
8989
computed: {
90-
// display the item from store state.
90+
// ストアのステートから item を表示します
9191
items () {
9292
return this.$store.state.items[this.$route.params.id]
9393
}
@@ -112,7 +112,7 @@ export default context => {
112112
if (!matchedComponents.length) {
113113
reject({ code: 404 })
114114
}
115-
// call asyncData() on all matched route components
115+
// マッチしたルートコンポーネントすべての asyncData() を呼び出します
116116
Promise.all(matchedComponents.map(Component => {
117117
if (Component.asyncData) {
118118
return Component.asyncData({
@@ -121,11 +121,10 @@ export default context => {
121121
})
122122
}
123123
})).then(() => {
124-
// After all preFetch hooks are resolved, our store is now
125-
// filled with the state needed to render the app.
126-
// When we attach the state to the context, and the `template` option
127-
// is used for the renderer, the state will automatically be
128-
// serialized and injected into the HTML as window.__INITIAL_STATE__.
124+
// すべてのプリフェッチのフックが解決されると、ストアには、
125+
// アプリケーションをレンダリングするために必要とされるステートが入っています。
126+
// ステートを context に付随させ、`template` オプションがレンダラーに利用されると、
127+
// ステートは自動的にシリアライズされ、HTML 内に `window.__INITIAL_STATE__` として埋め込まれます
129128
context.state = store.state
130129
resolve(app)
131130
}).catch(reject)
@@ -156,31 +155,31 @@ if (window.__INITIAL_STATE__) {
156155

157156
```js
158157
// entry-client.js
159-
// ...omitting unrelated code
158+
// 関係のないコードは除外します
160159
router.onReady(() => {
161-
// Add router hook for handling asyncData.
162-
// Doing it after initial route is resolved so that we don't double-fetch
163-
// the data that we already have. Using router.beforeResolve() so that all
164-
// async components are resolved.
160+
// asyncData を扱うためにルーターのフックを追加します。これは初期ルートが解決された後に実行します
161+
// そうすれば(訳注: サーバーサイドで取得したために)既に持っているデータを冗長に取得しなくて済みます
162+
// すべての非同期なコンポーネントが解決されるように router.beforeResolve() を使います
165163
router.beforeResolve((to, from, next) => {
166164
const matched = router.getMatchedComponents(to)
167165
const prevMatched = router.getMatchedComponents(from)
168-
// we only care about none-previously-rendered components,
169-
// so we compare them until the two matched lists differ
166+
// まだレンダリングされていないコンポーネントにのみ関心を払うため、
167+
// 2つのマッチしたリストに差分が表れるまで、コンポーネントを比較します
170168
let diffed = false
171169
const activated = matched.filter((c, i) => {
172170
return diffed || (diffed = (prevMatched[i] !== c))
173171
})
174172
if (!activated.length) {
175173
return next()
176174
}
177-
// this is where we should trigger a loading indicator if there is one
175+
// もしローディングインジケーターがあるならば、
176+
// この箇所がローディングインジケーターを発火させるべき箇所です
178177
Promise.all(activated.map(c => {
179178
if (c.asyncData) {
180179
return c.asyncData({ store, route: to })
181180
}
182181
})).then(() => {
183-
// stop loading indicator
182+
// ローディングインジケーターを停止させます
184183
next()
185184
}).catch(next)
186185
})
@@ -199,9 +198,8 @@ if (window.__INITIAL_STATE__) {
199198
beforeMount () {
200199
const { asyncData } = this.$options
201200
if (asyncData) {
202-
// assign the fetch operation to a promise
203-
// so that in components we can do `this.dataPromise.then(...)` to
204-
// perform other tasks after data is ready
201+
// データが準備できた後に、コンポーネント内で `this.dataPromise.then(...)` して
202+
// 他のタスクを実行できるようにするため、Promise にフェッチ処理を割り当てます
205203
this.dataPromise = asyncData({
206204
store: this.$store,
207205
route: this.$route

0 commit comments

Comments
 (0)