|
1 | 1 | /** |
2 | | - * vuex v3.1.2 |
3 | | - * (c) 2019 Evan You |
| 2 | + * vuex v3.1.3 |
| 3 | + * (c) 2020 Evan You |
4 | 4 | * @license MIT |
5 | 5 | */ |
6 | 6 | 'use strict'; |
@@ -394,7 +394,10 @@ Store.prototype.commit = function commit (_type, _payload, _options) { |
394 | 394 | handler(payload); |
395 | 395 | }); |
396 | 396 | }); |
397 | | - this._subscribers.forEach(function (sub) { return sub(mutation, this$1.state); }); |
| 397 | + |
| 398 | + this._subscribers |
| 399 | + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe |
| 400 | + .forEach(function (sub) { return sub(mutation, this$1.state); }); |
398 | 401 |
|
399 | 402 | if ( |
400 | 403 | process.env.NODE_ENV !== 'production' && |
@@ -426,6 +429,7 @@ Store.prototype.dispatch = function dispatch (_type, _payload) { |
426 | 429 |
|
427 | 430 | try { |
428 | 431 | this._actionSubscribers |
| 432 | + .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe |
429 | 433 | .filter(function (sub) { return sub.before; }) |
430 | 434 | .forEach(function (sub) { return sub.before(action, this$1.state); }); |
431 | 435 | } catch (e) { |
@@ -794,9 +798,7 @@ function enableStrictMode (store) { |
794 | 798 | } |
795 | 799 |
|
796 | 800 | function getNestedState (state, path) { |
797 | | - return path.length |
798 | | - ? path.reduce(function (state, key) { return state[key]; }, state) |
799 | | - : state |
| 801 | + return path.reduce(function (state, key) { return state[key]; }, state) |
800 | 802 | } |
801 | 803 |
|
802 | 804 | function unifyObjectStyle (type, payload, options) { |
@@ -1039,7 +1041,7 @@ function getModuleByNamespace (store, helper, namespace) { |
1039 | 1041 | var index = { |
1040 | 1042 | Store: Store, |
1041 | 1043 | install: install, |
1042 | | - version: '3.1.2', |
| 1044 | + version: '3.1.3', |
1043 | 1045 | mapState: mapState, |
1044 | 1046 | mapMutations: mapMutations, |
1045 | 1047 | mapGetters: mapGetters, |
|
0 commit comments