Skip to content

Commit

Permalink
update ja docs (vuejs#779)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kazupon authored and yyx990803 committed May 15, 2017
1 parent 7409d4f commit 8a4e485
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
20 changes: 14 additions & 6 deletions docs/ja/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ const store = new Vuex.Store({ ...options })

```
state, // モジュール内で定義されていればモジュールのローカルステート
getters, // store.getters と同じ
rootState // store.state と同じ
getters // store.getters と同じ
```

モジュールで定義されたときの仕様

```
state, // モジュールで定義された場合、モジュールのローカルステート
getters, // 現在のモジュールのモジュールのローカルゲッター
rootState, // グローバルステート
rootGetters // 全てのゲッター
```

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

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

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

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

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

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

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

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

`store.unregisterModule(moduleName)` を呼び出せば、動的に登録したモジュールを削除できます。ただしストア作成(store creation)の際に宣言された、静的なモジュールはこのメソッドで削除できないことに注意してください。

### モジュールの再利用

時どき、モジュールの複数インスタンスを作成する必要があるかもしれません。例えば:

- 同じモジュールを使用する複数のストアを作成する;
- 同じストアに同じモジュールを複数回登録する

モジュールの状態を宣言するために単純なオブジェクトを使用すると、その状態オブジェクトは参照によって共有され、変更時にクロスストア/モジュールの状態汚染を引き起こします。

これは、実際には Vue コンポーネント内部の `data` と全く同じ問題です。従って解決策も同じです。モジュールの状態を宣言するために関数を使用してください (2.3.0 以降でサポートされます):

``` js
const MyReusableModule = {
state () {
return {
foo: 'bar'
}
},
// ミューテーション、アクション、ゲッター...
}
```
5 changes: 4 additions & 1 deletion docs/ja/mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ export default {
// ...
methods: {
...mapMutations([
'increment' // this.increment() を this.$store.commit('increment') にマッピングする
'increment', // this.increment() を this.$store.commit('increment') にマッピングする
// mapMutations はペイロードサポートする:
'incrementBy' // this.incrementBy(amount) を this.$store.commit('incrementBy', amount) にマッピングする
]),
...mapMutations({
add: 'increment' // this.add() を this.$store.commit('increment') にマッピングする
Expand Down
3 changes: 2 additions & 1 deletion docs/ja/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ const store = new Vuex.Store({
const logger = createLogger({
collapsed: false, // ログ出力されたミューテーションを自動で展開します
filter (mutation, stateBefore, stateAfter) {
// ミューテーションを記録する必要がある場合は、true を返します
// returns true if a mutation should be logged
// `mutation` is a { type, payload }
// `mutation` { type, payload } です
return mutation.type !== "aBlacklistedMutation"
},
transformer (state) {
Expand Down
2 changes: 1 addition & 1 deletion docs/ja/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Counter = {
コンポーネントが複数のストアのステートプロパティやゲッターを必要としているとき、これらすべてにおいて、算出プロパティを宣言することは繰り返しで冗長です。これに対処するため、算出ゲッター関数を生成し、いくつかのキーストロークを節約するのに役立つ `mapState` ヘルパーを使うことができます:

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

export default {
Expand Down

0 comments on commit 8a4e485

Please sign in to comment.