Skip to content

Commit 8a4e485

Browse files
kazuponyyx990803
authored andcommitted
update ja docs (vuejs#779)
* add module getters definition explain * translate previous commit * add example of passing payload to mutation with mapMutations helper NOTE: pick up from vuejs@5f6b534 * translate previous commit * add mouse reuse docs * translate previous commit * fix typo NOTE: pick up from vuejs@72107ac * translate plugins section NOTE: reference from vuejs@8029c39 * add describe options argument of dispatch/commit in api docs NOTE: pick up from vuejs@1b889aa * translate previous commit * update state section NOTE: pick up from vuejs@7aad4a3 * remove origin
1 parent 7409d4f commit 8a4e485

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

docs/ja/api.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@ const store = new Vuex.Store({ ...options })
5252

5353
```
5454
state, // モジュール内で定義されていればモジュールのローカルステート
55-
getters, // store.getters と同じ
56-
rootState // store.state と同じ
55+
getters // store.getters と同じ
56+
```
57+
58+
モジュールで定義されたときの仕様
59+
60+
```
61+
state, // モジュールで定義された場合、モジュールのローカルステート
62+
getters, // 現在のモジュールのモジュールのローカルゲッター
63+
rootState, // グローバルステート
64+
rootGetters // 全てのゲッター
5765
```
5866

5967
登録されたゲッターは `store.getters` 上に公開されます。
@@ -117,13 +125,13 @@ const store = new Vuex.Store({ ...options })
117125

118126
### Vuex.Store インスタンスメソッド
119127

120-
- **`commit(type: string, payload?: any) | commit(mutation: Object)`**
128+
- **`commit(type: string, payload?: any, options?: Object) | commit(mutation: Object, options?: Object)`**
121129

122-
ミューテーションをコミットします。[詳細](mutations.md)
130+
ミューテーションをコミットします。`options` は[名前空間付きモジュール](modules.md#名前空間)で root なミューテーションにコミットできる `root: true` を持つことできます。[詳細](mutations.md)
123131

124-
- **`dispatch(type: string, payload?: any) | dispatch(action: Object)`**
132+
- **`dispatch(type: string, payload?: any, options?: Object) | dispatch(action: Object, options?: Object)`**
125133

126-
アクションをディスパッチします。すべてのトリガーされたアクションハンドラを解決するPromiseを返します。[詳細](actions.md)
134+
アクションをディスパッチします。`options` は[名前空間付きモジュール](modules.md#名前空間)で root なアクションにディスパッチできる `root: true` を持つことできます。 すべてのトリガーされたアクションハンドラを解決するPromiseを返します。[詳細](actions.md)
127135

128136
- **`replaceState(state: Object)`**
129137

docs/ja/modules.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,25 @@ store.registerModule(['nested', 'myModule'], {
243243
動的なモジュール登録があることで、他の Vue プラグインが、モジュールをアプリケーションのストアに付属させることで、状態の管理に Vuex を活用できることができます。例えば [`vuex-router-sync`](https://github.com/vuejs/vuex-router-sync) ライブラリは、動的に付属させたモジュール内部でアプリケーションのルーティングのステートを管理することで vue-router と vuex を統合しています。
244244

245245
`store.unregisterModule(moduleName)` を呼び出せば、動的に登録したモジュールを削除できます。ただしストア作成(store creation)の際に宣言された、静的なモジュールはこのメソッドで削除できないことに注意してください。
246+
247+
### モジュールの再利用
248+
249+
時どき、モジュールの複数インスタンスを作成する必要があるかもしれません。例えば:
250+
251+
- 同じモジュールを使用する複数のストアを作成する;
252+
- 同じストアに同じモジュールを複数回登録する
253+
254+
モジュールの状態を宣言するために単純なオブジェクトを使用すると、その状態オブジェクトは参照によって共有され、変更時にクロスストア/モジュールの状態汚染を引き起こします。
255+
256+
これは、実際には Vue コンポーネント内部の `data` と全く同じ問題です。従って解決策も同じです。モジュールの状態を宣言するために関数を使用してください (2.3.0 以降でサポートされます):
257+
258+
``` js
259+
const MyReusableModule = {
260+
state () {
261+
return {
262+
foo: 'bar'
263+
}
264+
},
265+
// ミューテーション、アクション、ゲッター...
266+
}
267+
```

docs/ja/mutations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ export default {
165165
// ...
166166
methods: {
167167
...mapMutations([
168-
'increment' // this.increment() を this.$store.commit('increment') にマッピングする
168+
'increment', // this.increment() を this.$store.commit('increment') にマッピングする
169+
170+
// mapMutations はペイロードサポートする:
171+
'incrementBy' // this.incrementBy(amount) を this.$store.commit('incrementBy', amount) にマッピングする
169172
]),
170173
...mapMutations({
171174
add: 'increment' // this.add() を this.$store.commit('increment') にマッピングする

docs/ja/plugins.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ const store = new Vuex.Store({
103103
const logger = createLogger({
104104
collapsed: false, // ログ出力されたミューテーションを自動で展開します
105105
filter (mutation, stateBefore, stateAfter) {
106+
// ミューテーションを記録する必要がある場合は、true を返します
106107
// returns true if a mutation should be logged
107-
// `mutation` is a { type, payload }
108+
// `mutation` { type, payload } です
108109
return mutation.type !== "aBlacklistedMutation"
109110
},
110111
transformer (state) {

docs/ja/state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const Counter = {
6060
コンポーネントが複数のストアのステートプロパティやゲッターを必要としているとき、これらすべてにおいて、算出プロパティを宣言することは繰り返しで冗長です。これに対処するため、算出ゲッター関数を生成し、いくつかのキーストロークを節約するのに役立つ `mapState` ヘルパーを使うことができます:
6161

6262
```js
63-
// スタンドアローンビルドでは、ヘルパーは Vuex.mapState として公開されています
63+
// 完全ビルドでは、ヘルパーは Vuex.mapState として公開されています
6464
import { mapState } from 'vuex'
6565

6666
export default {

0 commit comments

Comments
 (0)