1
0
Эх сурвалжийг харах

docs(ja): update the latest changes (#1750)

* docs(ja): update the latest changes

* docs(ja): fix typo
Kia King Ishii 5 жил өмнө
parent
commit
7807af7fcb

+ 14 - 1
docs/ja/api/README.md

@@ -234,7 +234,20 @@ const store = new Vuex.Store({ ...options })
   })
   ```
 
- プラグインで最も一般的に使用されます。[詳細](../guide/plugins.md)
+  > 3.4.0 で新規追加
+
+  3.4.0から、`subscribeAction` に `error` ハンドラが追加されました。このハンドラでは、アクションディスパッチの中で投げられたエラーをキャッチすることができます。`error` ハンドラは投げられた `error` オブジェクトを第3引数として受け取ります。
+
+  ``` js
+  store.subscribeAction({
+    error: (action, state, error) => {
+      console.log(`error action ${action.type}`)
+      console.error(error)
+    }
+  })
+  ```
+
+ `subscribeAction` メソッドはプラグインで最も一般的に使用されます。[詳細](../guide/plugins.md)
 
 ### registerModule
 

+ 47 - 0
docs/ja/guide/hot-reload.md

@@ -42,3 +42,50 @@ if (module.hot) {
 ```
 
 ホットリローディングを試したい場合は、[counter-hot example](https://github.com/vuejs/vuex/tree/dev/examples/counter-hot)をチェックアウトしてください。
+
+## 動的モジュールホットリローディング
+
+もしストアでモジュールだけを使用している場合には、`require.context` を使って全てのモジュールを動的に読み込むこともできます。
+
+```js
+// store.js
+import Vue from 'vue'
+import Vuex from 'vuex'
+
+// 全てのモジュールをロードする
+function loadModules() {
+  const context = require.context("./modules", false, /([a-z_]+)\.js$/i)
+
+  const modules = context
+    .keys()
+    .map((key) => ({ key, name: key.match(/([a-z_]+)\.js$/i)[1] }))
+    .reduce(
+      (modules, { key, name }) => ({
+        ...modules,
+        [name]: context(key).default
+      }),
+      {}
+    )
+
+  return { context, modules }
+}
+
+const { context, modules } = loadModules()
+
+Vue.use(Vuex)
+
+const store = new Vuex.Store({
+  modules
+})
+
+if (module.hot) {
+  // モジュールに変更があった場合にホットリロードする
+  module.hot.accept(context.id, () => {
+    const { modules } = loadModules()
+
+    store.hotUpdate({
+      modules
+    })
+  })
+}
+```