Skip to content

Commit 7807af7

Browse files
authored
docs(ja): update the latest changes (#1750)
* docs(ja): update the latest changes * docs(ja): fix typo
1 parent d13f3fc commit 7807af7

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

docs/ja/api/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,20 @@ const store = new Vuex.Store({ ...options })
234234
})
235235
```
236236

237-
 プラグインで最も一般的に使用されます。[詳細](../guide/plugins.md)
237+
> 3.4.0 で新規追加
238+
239+
3.4.0から、`subscribeAction``error` ハンドラが追加されました。このハンドラでは、アクションディスパッチの中で投げられたエラーをキャッチすることができます。`error` ハンドラは投げられた `error` オブジェクトを第3引数として受け取ります。
240+
241+
``` js
242+
store.subscribeAction({
243+
error: (action, state, error) => {
244+
console.log(`error action ${action.type}`)
245+
console.error(error)
246+
}
247+
})
248+
```
249+
250+
 `subscribeAction` メソッドはプラグインで最も一般的に使用されます。[詳細](../guide/plugins.md)
238251

239252
### registerModule
240253

docs/ja/guide/hot-reload.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,50 @@ if (module.hot) {
4242
```
4343

4444
ホットリローディングを試したい場合は、[counter-hot example](https://github.com/vuejs/vuex/tree/dev/examples/counter-hot)をチェックアウトしてください。
45+
46+
## 動的モジュールホットリローディング
47+
48+
もしストアでモジュールだけを使用している場合には、`require.context` を使って全てのモジュールを動的に読み込むこともできます。
49+
50+
```js
51+
// store.js
52+
import Vue from 'vue'
53+
import Vuex from 'vuex'
54+
55+
// 全てのモジュールをロードする
56+
function loadModules() {
57+
const context = require.context("./modules", false, /([a-z_]+)\.js$/i)
58+
59+
const modules = context
60+
.keys()
61+
.map((key) => ({ key, name: key.match(/([a-z_]+)\.js$/i)[1] }))
62+
.reduce(
63+
(modules, { key, name }) => ({
64+
...modules,
65+
[name]: context(key).default
66+
}),
67+
{}
68+
)
69+
70+
return { context, modules }
71+
}
72+
73+
const { context, modules } = loadModules()
74+
75+
Vue.use(Vuex)
76+
77+
const store = new Vuex.Store({
78+
modules
79+
})
80+
81+
if (module.hot) {
82+
// モジュールに変更があった場合にホットリロードする
83+
module.hot.accept(context.id, () => {
84+
const { modules } = loadModules()
85+
86+
store.hotUpdate({
87+
modules
88+
})
89+
})
90+
}
91+
```

0 commit comments

Comments
 (0)