From 0d003952e6fae1ca8af19ba695ff1ec2931ede4f Mon Sep 17 00:00:00 2001 From: bobstrange Date: Mon, 28 Sep 2020 21:17:55 +0900 Subject: [PATCH 1/3] docs: translate composition-api-provide-inject into ja --- src/guide/composition-api-provide-inject.md | 57 +++++++++++---------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/guide/composition-api-provide-inject.md b/src/guide/composition-api-provide-inject.md index 715c35c3..02d74fd4 100644 --- a/src/guide/composition-api-provide-inject.md +++ b/src/guide/composition-api-provide-inject.md @@ -1,12 +1,14 @@ # Provide / Inject -> This guide assumes that you have already read [Provide / Inject](component-provide-inject.html), [Composition API Introduction](composition-api-introduction.html), and [Reactivity Fundamentals](reactivity-fundamentals.html). +> このページは、すでに [Provide / Inject](component-provide-inject.html)、[コンポジション API 導入](composition-api-introduction.html)、[リアクティブの基礎](reactivity-fundamentals.html)を読み終えていることを想定しています。 -We can use [provide / inject](component-provide-inject.html) with the Composition API as well. Both can only be called during [`setup()`](composition-api-setup.html) with a current active instance. +[provide / inject](component-provide-inject.html) は コンポジション API でも使うことができます。どちらも現在アクティブなインスタンスの [`setup()`](composition-api-setup.html) 中にのみ呼び出すことが可能です。 -## Scenario Background -Let's assume that we want to rewrite the following code, which contains a `MyMap` component that provides a `MyMarker` component with the user's location, using the Composition API. +## シナリオの背景 + +これから、コンポジション API を使用して、以下のコードを書き直そうとしているとしましょう。 +以下のコードでは、`MyMap` コンポーネントが `MyMaker` コンポーネントにユーザの位置情報を提供しています。 ```vue @@ -41,16 +43,17 @@ export default { ``` -## Using Provide +## Provide の使い方 -When using `provide` in `setup()`, we start by explicitly importing the method from `vue`. This allows us to define each property with its own invocation of `provide`. +`setup()` 内で `provide` を使う場合、始めに `vue` から明示的に `provide` をインポートします。 +これにより、 各プロパティについて `provide` の呼び出しで定義することができるようになります。 -The `provide` function allows you to define the property through two parameters: +`provide` 関数は2つの引数によってプロパティを定義できます: -1. The property's name (`` type) -2. The property's value +1. プロパティの名前 (`` 型) +2. プロパティの値 -Using our `MyMap` component, our provided values can be refactored as the following: +`MyMap` コンポーネントは、以下のようにリファクタリングすることができます: ```vue{7,14-20} @@ -77,16 +80,18 @@ export default { ``` -## Using Inject +## Inject の使い方 + +同様に `setup()` 内 `inject` を使う場合も `vue` から明示的に `inject` をインポートする必要があります。 +そうしておけば、これを呼び出すことで、注入された値をコンポーネントに公開する方法を定義することができるようになります。 -When using `inject` in `setup()`, we also need to explicitly import it from `vue`. Once we do so, this allows us to invoke it to define how we want to expose it to our component. +`inject` 関数は2つの引数をとります: -The `inject` function takes two parameters: +1. 注入されるプロパティ名 +2. デフォルト値 (**Optional**) -1. The name of the property to inject -2. A default value (**Optional**) +`MyMaker` コンポーネントは、以下のようにリファクタリングすることができます: -Using our `MyMarker` component, we can refactor it with the following code: ```vue{3,6-14} @@ -107,13 +112,13 @@ export default { ``` -## Reactivity +## リアクティブ -### Adding Reactivity +### リアクティブの追加 -To add reactivity between provided and injected values, we can use a [ref](reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs) or [reactive](reactivity-fundamentals.html#declaring-reactive-state) when providing a value. +提供された値と注入された値をリアクティブにするには、値を提供する際に [ref](reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs) または [reactive](reactivity-fundamentals.html#declaring-reactive-state) を使います。 -Using our `MyMap` component, our code can be updated as follows: +`MyMap` コンポーネントは、以下のように変更できます: ```vue{7,15-22} @@ -143,13 +148,13 @@ export default { ``` -Now, if anything changes in either property, the `MyMarker` component will automatically be updated as well! +これで、どちらかのプロパティに何か変更があった場合、`MyMaker` コンポーネントも自動的に更新されるようになります。 -### Mutating Reactive Properties +### リアクティブプロパティの変更 -When using reactive provide / inject values, **it is recommended to keep any mutations to reactive properties inside of the _provider_ whenever possible**. +リアクティブな provide / inject の値を使う場合、**リアクティブなプロパティに対しての変更は可能な限り _提供する側_ の内部に留めることが推奨されます** -For example, in the event we needed to change the user's location, we would ideally do this inside of our `MyMap` component. +例えば、以下の location を変更する必要があるイベントでは、location の変更は `MyMap` コンポーネント内で行われるのが理想的です。 ```vue{28-32} @@ -188,7 +193,7 @@ export default { ``` -However, there are times where we need to update the data inside of the component where the data is injected. In this scenario, we recommend providing a method that is responsible for mutating the reactive property. +しかし、データが注入されたコンポーネント側でデータを更新する必要がある場合もあります。そのような場合、リアクティブなプロパティを更新する責務を持つメソッドを提供することを推奨します。 ```vue{21-23,27} @@ -244,7 +249,7 @@ export default { ``` -Finally, we recommend using `readonly` on provided property if you want to ensure that the data passed through `provide` cannot be mutated by the injected component. +最後に、`provide` で渡したデータが、注入されたコンポーネント内で変更されないようにしたい場合は、提供するプロパティに `readonly` をつけることを推奨します。 ```vue{7,25-26} From dea785d7811b879dd60f7a40507269eabe5b5804 Mon Sep 17 00:00:00 2001 From: bobstrange Date: Tue, 29 Sep 2020 11:47:03 +0900 Subject: [PATCH 2/3] Update src/guide/composition-api-provide-inject.md Co-authored-by: kazuya kawaguchi --- src/guide/composition-api-provide-inject.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guide/composition-api-provide-inject.md b/src/guide/composition-api-provide-inject.md index 02d74fd4..239f0d95 100644 --- a/src/guide/composition-api-provide-inject.md +++ b/src/guide/composition-api-provide-inject.md @@ -88,7 +88,7 @@ export default { `inject` 関数は2つの引数をとります: 1. 注入されるプロパティ名 -2. デフォルト値 (**Optional**) +2. デフォルト値 (**任意**) `MyMaker` コンポーネントは、以下のようにリファクタリングすることができます: From bf4f54a26554db8fdd2da15cefef3e15c1d10c1d Mon Sep 17 00:00:00 2001 From: bobstrange Date: Tue, 29 Sep 2020 11:54:12 +0900 Subject: [PATCH 3/3] doc: Fix review feedback --- src/guide/composition-api-provide-inject.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/guide/composition-api-provide-inject.md b/src/guide/composition-api-provide-inject.md index 239f0d95..8ef77d52 100644 --- a/src/guide/composition-api-provide-inject.md +++ b/src/guide/composition-api-provide-inject.md @@ -4,11 +4,9 @@ [provide / inject](component-provide-inject.html) は コンポジション API でも使うことができます。どちらも現在アクティブなインスタンスの [`setup()`](composition-api-setup.html) 中にのみ呼び出すことが可能です。 - ## シナリオの背景 -これから、コンポジション API を使用して、以下のコードを書き直そうとしているとしましょう。 -以下のコードでは、`MyMap` コンポーネントが `MyMaker` コンポーネントにユーザの位置情報を提供しています。 +これから、コンポジション API を使用して、以下のコードを書き直そうとしているとしましょう。以下のコードでは、`MyMap` コンポーネントが `MyMaker` コンポーネントにユーザの位置情報を提供しています。 ```vue @@ -45,8 +43,7 @@ export default { ## Provide の使い方 -`setup()` 内で `provide` を使う場合、始めに `vue` から明示的に `provide` をインポートします。 -これにより、 各プロパティについて `provide` の呼び出しで定義することができるようになります。 +`provide` を `setup()` 内で使う場合、始めに `vue` から明示的に `provide` をインポートします。これにより、 各プロパティについて `provide` の呼び出しで定義することができるようになります。 `provide` 関数は2つの引数によってプロパティを定義できます: @@ -82,8 +79,7 @@ export default { ## Inject の使い方 -同様に `setup()` 内 `inject` を使う場合も `vue` から明示的に `inject` をインポートする必要があります。 -そうしておけば、これを呼び出すことで、注入された値をコンポーネントに公開する方法を定義することができるようになります。 +`inject` を `setup()` 内で使う場合も、`vue` から明示的に `inject` をインポートする必要があります。そうしておけば、これを呼び出すことで、注入された値をコンポーネントに公開する方法を定義することができるようになります。 `inject` 関数は2つの引数をとります: @@ -92,7 +88,6 @@ export default { `MyMaker` コンポーネントは、以下のようにリファクタリングすることができます: - ```vue{3,6-14}