Skip to content

Commit ae02c09

Browse files
authored
API Reference > Refs の翻訳 (#545)
* API Reference > Refs の翻訳 * 用語統一 + シュガーを分かりやすく
1 parent e6486cd commit ae02c09

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

src/api/reactivity-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
リアクティビティ API には、次のようなセクションがあります:
44

55
- [基本のリアクティビティ API](/api/basic-reactivity.html)
6-
- [Refs](/api/refs-api.html)
6+
- [ref 関連](/api/refs-api.html)
77
- [computed と watch](/api/computed-watch-api.html)
88
- [Effect Scope API](/api/effect-scope.html)

src/api/refs-api.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Refs
1+
# ref 関連
22

3-
> This section uses [single-file component](../guide/single-file-component.html) syntax for code examples
3+
> このセクションでは、コード例に [単一ファイルコンポーネント](../guide/single-file-component.html) 構文を使用します
44
55
## `ref`
66

7-
Takes an inner value and returns a reactive and mutable ref object. The ref object has a single property `.value` that points to the inner value.
7+
内部の値を受け取り、リアクティブでミュータブルな ref オブジェクトを返します。ref オブジェクトには、内部の値を指す単一のプロパティ `.value` があります。
88

9-
**Example:**
9+
**:**
1010

1111
```js
1212
const count = ref(0)
@@ -16,9 +16,9 @@ count.value++
1616
console.log(count.value) // 1
1717
```
1818

19-
If an object is assigned as a ref's value, the object is made deeply reactive by the [reactive](./basic-reactivity.html#reactive) function.
19+
ref の値としてオブジェクトが割り当てられている場合、そのオブジェクトは [reactive](./basic-reactivity.html#reactive) 関数によってディープなリアクティブになります。
2020

21-
**Typing:**
21+
**:**
2222

2323
```ts
2424
interface Ref<T> {
@@ -28,15 +28,15 @@ interface Ref<T> {
2828
function ref<T>(value: T): Ref<T>
2929
```
3030

31-
Sometimes we may need to specify complex types for a ref's inner value. We can do that succinctly by passing a generics argument when calling `ref` to override the default inference:
31+
場合によっては、ref の内部値に複合の型を指定する必要があります。そのような場合には、`ref` を呼び出す際にジェネリクス引数を渡して、デフォルトの推論をオーバーライドすることで、簡潔に指定できます。
3232

3333
```ts
34-
const foo = ref<string | number>('foo') // foo's type: Ref<string | number>
34+
const foo = ref<string | number>('foo') // foo の型: Ref<string | number>
3535
3636
foo.value = 123 // ok!
3737
```
3838

39-
If the type of the generic is unknown, it's recommended to cast `ref` to `Ref<T>`:
39+
ジェネリックの型が不明な場合は、`ref` `Ref<T>` にキャストすることをお勧めします:
4040

4141
```ts
4242
function useState<State extends string>(initial: State) {
@@ -47,17 +47,17 @@ function useState<State extends string>(initial: State) {
4747

4848
## `unref`
4949

50-
Returns the inner value if the argument is a [`ref`](#ref), otherwise return the argument itself. This is a sugar function for `val = isRef(val) ? val.value : val`.
50+
引数が [`ref`](#ref) の場合はその内部の値を、そうでない場合は引数そのものを返します。これは、`val = isRef(val) ? val.value : val` のシュガー(簡易)関数です。
5151

5252
```ts
5353
function useFoo(x: number | Ref<number>) {
54-
const unwrapped = unref(x) // unwrapped is guaranteed to be number now
54+
const unwrapped = unref(x) // unwrapped number であることが保証されます
5555
}
5656
```
5757

5858
## `toRef`
5959

60-
Can be used to create a [`ref`](#ref) for a property on a source reactive object. The ref can then be passed around, retaining the reactive connection to its source property.
60+
ソースとなるリアクティブオブジェクトのプロパティに対する [`ref`](#ref) を作成するために使用できます。この ref は、ソースのプロパティへのリアクティブな接続を維持したまま、引き渡すことができます。
6161

6262
```js
6363
const state = reactive({
@@ -74,7 +74,7 @@ state.foo++
7474
console.log(fooRef.value) // 3
7575
```
7676

77-
`toRef` is useful when you want to pass the ref of a prop to a composition function:
77+
`toRef` は、propref composition 関数に渡したいときに便利です:
7878

7979
```js
8080
export default {
@@ -84,11 +84,11 @@ export default {
8484
}
8585
```
8686

87-
`toRef` will return a usable ref even if the source property doesn't currently exist. This makes it especially useful when working with optional props, which wouldn't be picked up by [`toRefs`](#torefs).
87+
`toRef` は、ソースとなるプロパティが現在存在しない場合でも、使用可能な ref を返します。これは、[toRefs`](#torefs) で取得されない省略可能な props を扱うときに特に便利です。
8888
8989
## `toRefs`
9090
91-
Converts a reactive object to a plain object where each property of the resulting object is a [`ref`](#ref) pointing to the corresponding property of the original object.
91+
リアクティブなオブジェクトをプレーンオブジェクトに変換します。変換後のオブジェクトの各プロパティは、元のオブジェクトの対応するプロパティを指す [`ref`](#ref) となります。
9292
9393
```js
9494
const state = reactive({
@@ -98,23 +98,23 @@ const state = reactive({
9898

9999
const stateAsRefs = toRefs(state)
100100
/*
101-
Type of stateAsRefs:
101+
stateAsRefs の型:
102102
103103
{
104104
foo: Ref<number>,
105105
bar: Ref<number>
106106
}
107107
*/
108108

109-
// The ref and the original property is "linked"
109+
// ref と元のプロパティは「リンク」している
110110
state.foo++
111111
console.log(stateAsRefs.foo.value) // 2
112112

113113
stateAsRefs.foo.value++
114114
console.log(state.foo) // 3
115115
```
116116
117-
`toRefs` is useful when returning a reactive object from a composition function so that the consuming component can destructure/spread the returned object without losing reactivity:
117+
`toRefs` は、composition 関数からリアクティブなオブジェクトを返すときに便利で、利用する側のコンポーネントはリアクティビティを失うことなく、返されたオブジェクトを分割代入できます:
118118
119119
```js
120120
function useFeatureX() {
@@ -123,15 +123,15 @@ function useFeatureX() {
123123
bar: 2
124124
})
125125

126-
// logic operating on state
126+
// 状態で動作するロジック
127127

128-
// convert to refs when returning
128+
// 返すときに ref に変換する
129129
return toRefs(state)
130130
}
131131

132132
export default {
133133
setup() {
134-
// can destructure without losing reactivity
134+
// リアクティビティを失うことなく分割代入できる
135135
const { foo, bar } = useFeatureX()
136136

137137
return {
@@ -142,17 +142,17 @@ export default {
142142
}
143143
```
144144
145-
`toRefs` will only generate refs for properties that are included in the source object. To create a ref for a specific property use [`toRef`](#toref) instead.
145+
`toRefs` はソースオブジェクトに含まれるプロパティの ref を生成するだけです。特定のプロパティのリファレンスを作成するには、代わりに [`toRef`](#toref) を使用してください。
146146
147147
## `isRef`
148148
149-
Checks if a value is a ref object.
149+
値が ref オブジェクトであるかどうかをチェックします。
150150
151151
## `customRef`
152152
153-
Creates a customized ref with explicit control over its dependency tracking and updates triggering. It expects a factory function, which receives `track` and `trigger` functions as arguments and should return an object with `get` and `set`.
153+
依存関係の追跡と更新のトリガを明示的に制御する、カスタマイズされた ref を作成します。`track` `trigger` 関数を引数として受け取り、`get` `set` を持つオブジェクトを返すファクトリ関数が必要です。
154154
155-
- Example using a custom ref to implement debounce with `v-model`:
155+
- `v-model` でデバウンスを実装するためにカスタム ref を使用した例:
156156
157157
```html
158158
<input v-model="text" />
@@ -187,7 +187,7 @@ Creates a customized ref with explicit control over its dependency tracking and
187187
}
188188
```
189189
190-
**Typing:**
190+
**:**
191191
192192
```ts
193193
function customRef<T>(factory: CustomRefFactory<T>): Ref<T>
@@ -203,37 +203,37 @@ type CustomRefFactory<T> = (
203203
204204
## `shallowRef`
205205
206-
Creates a ref that tracks its own `.value` mutation but doesn't make its value reactive.
206+
自分自身の `.value` の変更を追跡するが、その値をリアクティブにはしない ref を作成します。
207207
208208
```js
209209
const foo = shallowRef({})
210-
// mutating the ref's value is reactive
210+
// ref の値を変更するのはリアクティブ
211211
foo.value = {}
212-
// but the value will not be converted.
212+
// ただし、値は変換されない
213213
isReactive(foo.value) // false
214214
```
215215
216-
**See also**: [Creating Standalone Reactive Values as `refs`](../guide/reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs)
216+
**参照**: [独立したリアクティブな値を `ref` として作成する](../guide/reactivity-fundamentals.html#独立したリアクティブな値を-ref-として作成する)
217217
218218
## `triggerRef`
219219
220-
Execute any effects tied to a [`shallowRef`](#shallowref) manually.
220+
[`shallowRef`](#shallowref) に関連付けられている副作用を手動で実行します。
221221
222222
```js
223223
const shallow = shallowRef({
224224
greet: 'Hello, world'
225225
})
226226

227-
// Logs "Hello, world" once for the first run-through
227+
// 初回実行時に "Hello, world" と出力される
228228
watchEffect(() => {
229229
console.log(shallow.value.greet)
230230
})
231231

232-
// This won't trigger the effect because the ref is shallow
232+
// shallowRef なので、これでは副作用をトリガしません
233233
shallow.value.greet = 'Hello, universe'
234234

235-
// Logs "Hello, universe"
235+
// "Hello, universe" と出力
236236
triggerRef(shallow)
237237
```
238238
239-
**See also:** [Computed and Watch - watchEffect](./computed-watch-api.html#watcheffect)
239+
**参照:** [computed と watch - watchEffect](./computed-watch-api.html#watcheffect)

0 commit comments

Comments
 (0)