Skip to content

Commit af6971e

Browse files
committed
Merge branch 'dev' into 4.0
# Conflicts: # .gitignore # examples/chat/app.js # examples/classic/shopping-cart/app.js # examples/counter/app.js # examples/todomvc/app.js # package.json # rollup.config.js # rollup.main.config.js # scripts/build-main.js # scripts/release.sh # src/index.cjs.js # src/store.js # test/unit/helpers.spec.js # test/unit/hot-reload.spec.js # test/unit/modules.spec.js # test/unit/setup.js # test/unit/store.spec.js # types/tsconfig.json # yarn.lock
2 parents a934da9 + ce0c88a commit af6971e

38 files changed

+533
-283
lines changed

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"presets": ["env"],
3-
"plugins": ["transform-object-rest-spread"]
2+
"presets": ["@babel/preset-env"]
43
}
File renamed without changes.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
!/dist/logger.d.ts
33
/docs/.vuepress/dist
44
/examples/**/build.js
5-
/node_modules
5+
/coverage
6+
/docs/.vuepress/dist
7+
/examples/**/build.js
68
/test/e2e/reports
79
/test/e2e/screenshots
810
/types/typings
911
/types/test/*.js
1012
*.log
1113
.DS_Store
14+
node_modules

docs/api/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ const store = new Vuex.Store({ ...options })
185185
})
186186
```
187187
188-
By default, new handler is added to the end of the chain, so it will be executed after other handlers that were added before. This can be overriden by adding `prepend: true` to `options`, which will add the handler to the beginning of the chain.
188+
By default, new handler is added to the end of the chain, so it will be executed after other handlers that were added before. This can be overridden by adding `prepend: true` to `options`, which will add the handler to the beginning of the chain.
189189
190190
``` js
191191
store.subscribe(handler, { prepend: true })
@@ -210,10 +210,10 @@ const store = new Vuex.Store({ ...options })
210210
})
211211
```
212212
213-
By default, new handler is added to the end of the chain, so it will be executed after other handlers that were added before. This can be overriden by adding `prepend: true` to `options`, which will add the handler to the beginning of the chain.
213+
By default, new handler is added to the end of the chain, so it will be executed after other handlers that were added before. This can be overridden by adding `prepend: true` to `options`, which will add the handler to the beginning of the chain.
214214
215215
``` js
216-
store.subscribe(handler, { prepend: true })
216+
store.subscribeAction(handler, { prepend: true })
217217
```
218218
219219
To stop subscribing, call the returned unsubscribe function.
@@ -233,7 +233,20 @@ const store = new Vuex.Store({ ...options })
233233
})
234234
```
235235
236-
Most commonly used in plugins. [Details](../guide/plugins.md)
236+
> New in 3.4.0
237+
238+
Since 3.4.0, `subscribeAction` can also specify an `error` handler to catch an error thrown when an action is dispatched. The function will receive an `error` object as the third argument.
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+
The `subscribeAction` method is most commonly used in plugins. [Details](../guide/plugins.md)
237250
238251
### registerModule
239252

docs/fr/guide/modules.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ Pour y remédier, Vuex nous permet de diviser notre store en **modules**. Chaque
88

99
``` js
1010
const moduleA = {
11-
state: { ... },
11+
state: () => ({ ... }),
1212
mutations: { ... },
1313
actions: { ... },
1414
getters: { ... }
1515
}
1616

1717
const moduleB = {
18-
state: { ... },
18+
state: () => ({ ... }),
1919
mutations: { ... },
2020
actions: { ... }
2121
}
@@ -37,7 +37,9 @@ Dans les mutations et accesseurs d'un module, le premier argument reçu sera **l
3737

3838
``` js
3939
const moduleA = {
40-
state: { count: 0 },
40+
state: () => ({
41+
count: 0
42+
}),
4143
mutations: {
4244
increment (state) {
4345
// `state` est l'état du module local
@@ -87,14 +89,14 @@ Par défaut, les actions, mutations et accesseurs à l'intérieur d'un module so
8789

8890
Si vous souhaitez que votre module soit autosuffisant et réutilisable, vous pouvez le ranger sous un espace de nom avec `namespaced: true`. Quand le module est enregistré, tous ses accesseurs, actions et mutations seront automatiquement basés sur l'espace de nom du module dans lesquels ils sont rangés. Par exemple :
8991

90-
```js
92+
``` js
9193
const store = new Vuex.Store({
9294
modules: {
9395
account: {
9496
namespaced: true,
9597

9698
// propriétés du module
97-
state: { ... }, // l'état du module est déjà imbriqué et n'est pas affecté par l'option `namespace`
99+
state: () => ({ ... }), // l'état du module est déjà imbriqué et n'est pas affecté par l'option `namespace`
98100
getters: {
99101
isAdmin () { ... } // -> getters['account/isAdmin']
100102
},
@@ -109,7 +111,7 @@ const store = new Vuex.Store({
109111
modules: {
110112
// hérite de l'espace de nom du module parent
111113
myPage: {
112-
state: { ... },
114+
state: () => ({ ... }),
113115
getters: {
114116
profile () { ... } // -> getters['account/profile']
115117
}
@@ -119,7 +121,7 @@ const store = new Vuex.Store({
119121
posts: {
120122
namespaced: true,
121123

122-
state: { ... },
124+
state: () => ({ ... }),
123125
getters: {
124126
popular () { ... } // -> getters['account/posts/popular']
125127
}
@@ -262,7 +264,7 @@ export default {
262264

263265
Vous devez faire attention au nom d'espace imprévisible pour vos modules quand vous créez un [plugin](./plugins.md) qui fournit les modules et laisser les utilisateurs les ajouter au store de Vuex. Vos modules seront également sous espace de nom si l'utilisateur du plugin l'ajoute sous un module sous espace de nom. Pour vous adapter à la situation, vous devez recevoir la valeur de l'espace de nom via vos options de plugin :
264266

265-
```js
267+
``` js
266268
// passer la valeur d'espace de nom via une option du plugin
267269
// et retourner une fonction de plugin Vuex
268270
export function createPlugin (options = {}) {
@@ -311,11 +313,9 @@ C'est exactement le même problème qu'avec `data` dans un composant Vue. Ainsi
311313

312314
``` js
313315
const MyReusableModule = {
314-
state () {
315-
return {
316-
foo: 'bar'
317-
}
318-
},
316+
state: () => ({
317+
foo: 'bar'
318+
}),
319319
// mutations, actions, accesseurs...
320320
}
321321
```

docs/guide/modules.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ To help with that, Vuex allows us to divide our store into **modules**. Each mod
88

99
``` js
1010
const moduleA = {
11-
state: { ... },
11+
state: () => ({ ... }),
1212
mutations: { ... },
1313
actions: { ... },
1414
getters: { ... }
1515
}
1616

1717
const moduleB = {
18-
state: { ... },
18+
state: () => ({ ... }),
1919
mutations: { ... },
2020
actions: { ... }
2121
}
@@ -37,7 +37,9 @@ Inside a module's mutations and getters, the first argument received will be **t
3737

3838
``` js
3939
const moduleA = {
40-
state: { count: 0 },
40+
state: () => ({
41+
count: 0
42+
}),
4143
mutations: {
4244
increment (state) {
4345
// `state` is the local module state
@@ -94,7 +96,7 @@ const store = new Vuex.Store({
9496
namespaced: true,
9597

9698
// module assets
97-
state: { ... }, // module state is already nested and not affected by namespace option
99+
state: () => ({ ... }), // module state is already nested and not affected by namespace option
98100
getters: {
99101
isAdmin () { ... } // -> getters['account/isAdmin']
100102
},
@@ -109,7 +111,7 @@ const store = new Vuex.Store({
109111
modules: {
110112
// inherits the namespace from parent module
111113
myPage: {
112-
state: { ... },
114+
state: () => ({ ... }),
113115
getters: {
114116
profile () { ... } // -> getters['account/profile']
115117
}
@@ -119,7 +121,7 @@ const store = new Vuex.Store({
119121
posts: {
120122
namespaced: true,
121123

122-
state: { ... },
124+
state: () => ({ ... }),
123125
getters: {
124126
popular () { ... } // -> getters['account/posts/popular']
125127
}
@@ -322,11 +324,9 @@ This is actually the exact same problem with `data` inside Vue components. So th
322324

323325
``` js
324326
const MyReusableModule = {
325-
state () {
326-
return {
327-
foo: 'bar'
328-
}
329-
},
327+
state: () => ({
328+
foo: 'bar'
329+
}),
330330
// mutations, actions, getters...
331331
}
332332
```

docs/ja/api/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const store = new Vuex.Store({ ...options })
175175

176176
### subscribe
177177

178-
- `subscribe(handler: Function): Function`
178+
- `subscribe(handler: Function, options?: Object): Function`
179179

180180
ストアへのミューテーションを購読します。`handler` は、全てのミューテーションの後に呼ばれ、引数として、ミューテーション ディスクリプタとミューテーション後の状態を受け取ります。
181181

@@ -186,13 +186,19 @@ const store = new Vuex.Store({ ...options })
186186
})
187187
```
188188

189+
デフォルトでは、新しい `handler` はチェーンの最後に登録されます。つまり、先に追加された他の `handler` が呼び出された後に実行されます。`prepend: true``options` に設定することで、`handler` をチェーンの最初に登録することができます。
190+
191+
``` js
192+
store.subscribe(handler, { prepend: true })
193+
```
194+
189195
購読を停止するには、返された unsubscribe 関数呼び出します。
190196

191197
プラグインの中でもっともよく利用されます。[詳細](../guide/plugins.md)
192198

193199
### subscribeAction
194200

195-
- `subscribeAction(handler: Function)`
201+
- `subscribeAction(handler: Function, options?: Object): Function`
196202

197203
> 2.5.0 で新規追加
198204

@@ -205,6 +211,12 @@ const store = new Vuex.Store({ ...options })
205211
})
206212
```
207213

214+
デフォルトでは、新しい `handler` はチェーンの最後に登録されます。つまり、先に追加された他の `handler` が呼び出された後に実行されます。`prepend: true``options` に設定することで、`handler` をチェーンの最初に登録することができます。
215+
216+
``` js
217+
store.subscribeAction(handler, { prepend: true })
218+
```
219+
208220
 購読を停止するには、返された購読解除関数を呼びます。
209221

210222
> 3.1.0 で新規追加

docs/ja/guide/modules.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
``` js
1010
const moduleA = {
11-
state: { ... },
11+
state: () => ({ ... }),
1212
mutations: { ... },
1313
actions: { ... },
1414
getters: { ... }
1515
}
1616

1717
const moduleB = {
18-
state: { ... },
18+
state: () => ({ ... }),
1919
mutations: { ... },
2020
actions: { ... }
2121
}
@@ -37,7 +37,9 @@ store.state.b // -> `moduleB` のステート
3737

3838
``` js
3939
const moduleA = {
40-
state: { count: 0 },
40+
state: () => ({
41+
count: 0
42+
}),
4143
mutations: {
4244
increment (state) {
4345
// `state` はモジュールのローカルステート
@@ -94,7 +96,7 @@ const store = new Vuex.Store({
9496
namespaced: true,
9597

9698
// モジュールのアセット
97-
state: { ... }, // モジュールステートはすでにネストされており、名前空間のオプションによって影響を受けません
99+
state: () => ({ ... }), // モジュールステートはすでにネストされており、名前空間のオプションによって影響を受けません
98100
getters: {
99101
isAdmin () { ... } // -> getters['account/isAdmin']
100102
},
@@ -109,7 +111,7 @@ const store = new Vuex.Store({
109111
modules: {
110112
// 親モジュールから名前空間を継承する
111113
myPage: {
112-
state: { ... },
114+
state: () => ({ ... }),
113115
getters: {
114116
profile () { ... } // -> getters['account/profile']
115117
}
@@ -119,7 +121,7 @@ const store = new Vuex.Store({
119121
posts: {
120122
namespaced: true,
121123

122-
state: { ... },
124+
state: () => ({ ... }),
123125
getters: {
124126
popular () { ... } // -> getters['account/posts/popular']
125127
}
@@ -318,11 +320,9 @@ store.registerModule(['nested', 'myModule'], {
318320

319321
``` js
320322
const MyReusableModule = {
321-
state () {
322-
return {
323-
foo: 'bar'
324-
}
325-
},
323+
state: () => ({
324+
foo: 'bar'
325+
}),
326326
// ミューテーション、アクション、ゲッター...
327327
}
328328
```

docs/ja/guide/plugins.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,27 @@ const logger = createLogger({
109109
// `mutation` は `{ type, payload }` です
110110
return mutation.type !== "aBlacklistedMutation"
111111
},
112+
actionFilter (action, state) {
113+
// `filter` と同等ですが、アクション用です
114+
// `action` は `{ type, payloed }` です
115+
return action.type !== "aBlacklistedAction"
116+
},
112117
transformer (state) {
113118
// ロギングの前に、状態を変換します
114119
// 例えば、特定のサブツリーのみを返します
115120
return state.subTree
116121
},
122+
actionTransformer (action) {
123+
// `mutationTransformer` と同等ですが、アクション用です
124+
return action.type
125+
},
117126
mutationTransformer (mutation) {
118127
// ミューテーションは、`{ type, payload }` の形式でログ出力されます
119128
// 任意の方法でそれをフォーマットできます
120129
return mutation.type
121130
},
131+
logActions: true, // アクションログを出力します。
132+
logMutations: true, // ミューテーションログを出力します。
122133
logger: console, // `console` API の実装, デフォルトは `console`
123134
})
124135
```

0 commit comments

Comments
 (0)