Skip to content

Commit d13f3fc

Browse files
authored
docs(ru): translation update (#1747)
Co-authored-by: Alex Sokolov <[email protected]>
1 parent 8691e61 commit d13f3fc

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

docs/ru/api/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,20 @@ store.subscribeAction({
233233
})
234234
```
235235
236-
Чаще всего используется в плагинах. [Подробнее](../guide/plugins.md)
236+
> Добавлено в версии 3.4.0
237+
238+
С версии 3.4.0 в `subscribeAction` также можно указывать обработчик `error` для перехвата ошибки, выброшенной при выполнении действия. В качестве третьего аргумента функция получает объект `error`.
239+
240+
``` js
241+
store.subscribeAction({
242+
error: (action, state, error) => {
243+
console.log(`error action ${action.type}`)
244+
console.error(error)
245+
}
246+
})
247+
```
248+
249+
Метод `subscribeAction` чаще всего используется в плагинах. [Подробнее](../guide/plugins.md)
237250
238251
### registerModule
239252

docs/ru/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](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)