Skip to content

Commit 1ed9a03

Browse files
committed
[build] 3.1.2
1 parent d4d0430 commit 1ed9a03

File tree

6 files changed

+252
-96
lines changed

6 files changed

+252
-96
lines changed

Diff for: dist/vuex.common.js

+62-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vuex v3.1.1
2+
* vuex v3.1.2
33
* (c) 2019 Evan You
44
* @license MIT
55
*/
@@ -323,6 +323,7 @@ var Store = function Store (options) {
323323
this._modulesNamespaceMap = Object.create(null);
324324
this._subscribers = [];
325325
this._watcherVM = new Vue();
326+
this._makeLocalGettersCache = Object.create(null);
326327

327328
// bind commit and dispatch to self
328329
var store = this;
@@ -555,12 +556,14 @@ function resetStoreVM (store, state, hot) {
555556

556557
// bind store public getters
557558
store.getters = {};
559+
// reset local getters cache
560+
store._makeLocalGettersCache = Object.create(null);
558561
var wrappedGetters = store._wrappedGetters;
559562
var computed = {};
560563
forEachValue(wrappedGetters, function (fn, key) {
561564
// use computed to leverage its lazy-caching mechanism
562565
// direct inline function use will lead to closure preserving oldVm.
563-
// using partial to return function with only arguments preserved in closure enviroment.
566+
// using partial to return function with only arguments preserved in closure environment.
564567
computed[key] = partial(fn, store);
565568
Object.defineProperty(store.getters, key, {
566569
get: function () { return store._vm[key]; },
@@ -604,6 +607,9 @@ function installModule (store, rootState, path, module, hot) {
604607

605608
// register in namespace map
606609
if (module.namespaced) {
610+
if (store._modulesNamespaceMap[namespace] && process.env.NODE_ENV !== 'production') {
611+
console.error(("[vuex] duplicate namespace " + namespace + " for the namespaced module " + (path.join('/'))));
612+
}
607613
store._modulesNamespaceMap[namespace] = module;
608614
}
609615

@@ -612,6 +618,13 @@ function installModule (store, rootState, path, module, hot) {
612618
var parentState = getNestedState(rootState, path.slice(0, -1));
613619
var moduleName = path[path.length - 1];
614620
store._withCommit(function () {
621+
if (process.env.NODE_ENV !== 'production') {
622+
if (moduleName in parentState) {
623+
console.warn(
624+
("[vuex] state field \"" + moduleName + "\" was overridden by a module with the same name at \"" + (path.join('.')) + "\"")
625+
);
626+
}
627+
}
615628
Vue.set(parentState, moduleName, module.state);
616629
});
617630
}
@@ -699,26 +712,28 @@ function makeLocalContext (store, namespace, path) {
699712
}
700713

701714
function makeLocalGetters (store, namespace) {
702-
var gettersProxy = {};
703-
704-
var splitPos = namespace.length;
705-
Object.keys(store.getters).forEach(function (type) {
706-
// skip if the target getter is not match this namespace
707-
if (type.slice(0, splitPos) !== namespace) { return }
708-
709-
// extract local getter type
710-
var localType = type.slice(splitPos);
711-
712-
// Add a port to the getters proxy.
713-
// Define as getter property because
714-
// we do not want to evaluate the getters in this time.
715-
Object.defineProperty(gettersProxy, localType, {
716-
get: function () { return store.getters[type]; },
717-
enumerable: true
715+
if (!store._makeLocalGettersCache[namespace]) {
716+
var gettersProxy = {};
717+
var splitPos = namespace.length;
718+
Object.keys(store.getters).forEach(function (type) {
719+
// skip if the target getter is not match this namespace
720+
if (type.slice(0, splitPos) !== namespace) { return }
721+
722+
// extract local getter type
723+
var localType = type.slice(splitPos);
724+
725+
// Add a port to the getters proxy.
726+
// Define as getter property because
727+
// we do not want to evaluate the getters in this time.
728+
Object.defineProperty(gettersProxy, localType, {
729+
get: function () { return store.getters[type]; },
730+
enumerable: true
731+
});
718732
});
719-
});
733+
store._makeLocalGettersCache[namespace] = gettersProxy;
734+
}
720735

721-
return gettersProxy
736+
return store._makeLocalGettersCache[namespace]
722737
}
723738

724739
function registerMutation (store, type, handler, local) {
@@ -730,15 +745,15 @@ function registerMutation (store, type, handler, local) {
730745

731746
function registerAction (store, type, handler, local) {
732747
var entry = store._actions[type] || (store._actions[type] = []);
733-
entry.push(function wrappedActionHandler (payload, cb) {
748+
entry.push(function wrappedActionHandler (payload) {
734749
var res = handler.call(store, {
735750
dispatch: local.dispatch,
736751
commit: local.commit,
737752
getters: local.getters,
738753
state: local.state,
739754
rootGetters: store.getters,
740755
rootState: store.state
741-
}, payload, cb);
756+
}, payload);
742757
if (!isPromise(res)) {
743758
res = Promise.resolve(res);
744759
}
@@ -819,6 +834,9 @@ function install (_Vue) {
819834
*/
820835
var mapState = normalizeNamespace(function (namespace, states) {
821836
var res = {};
837+
if (process.env.NODE_ENV !== 'production' && !isValidMap(states)) {
838+
console.error('[vuex] mapState: mapper parameter must be either an Array or an Object');
839+
}
822840
normalizeMap(states).forEach(function (ref) {
823841
var key = ref.key;
824842
var val = ref.val;
@@ -852,6 +870,9 @@ var mapState = normalizeNamespace(function (namespace, states) {
852870
*/
853871
var mapMutations = normalizeNamespace(function (namespace, mutations) {
854872
var res = {};
873+
if (process.env.NODE_ENV !== 'production' && !isValidMap(mutations)) {
874+
console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object');
875+
}
855876
normalizeMap(mutations).forEach(function (ref) {
856877
var key = ref.key;
857878
var val = ref.val;
@@ -885,6 +906,9 @@ var mapMutations = normalizeNamespace(function (namespace, mutations) {
885906
*/
886907
var mapGetters = normalizeNamespace(function (namespace, getters) {
887908
var res = {};
909+
if (process.env.NODE_ENV !== 'production' && !isValidMap(getters)) {
910+
console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object');
911+
}
888912
normalizeMap(getters).forEach(function (ref) {
889913
var key = ref.key;
890914
var val = ref.val;
@@ -915,6 +939,9 @@ var mapGetters = normalizeNamespace(function (namespace, getters) {
915939
*/
916940
var mapActions = normalizeNamespace(function (namespace, actions) {
917941
var res = {};
942+
if (process.env.NODE_ENV !== 'production' && !isValidMap(actions)) {
943+
console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object');
944+
}
918945
normalizeMap(actions).forEach(function (ref) {
919946
var key = ref.key;
920947
var val = ref.val;
@@ -960,11 +987,23 @@ var createNamespacedHelpers = function (namespace) { return ({
960987
* @return {Object}
961988
*/
962989
function normalizeMap (map) {
990+
if (!isValidMap(map)) {
991+
return []
992+
}
963993
return Array.isArray(map)
964994
? map.map(function (key) { return ({ key: key, val: key }); })
965995
: Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); })
966996
}
967997

998+
/**
999+
* Validate whether given map is valid or not
1000+
* @param {*} map
1001+
* @return {Boolean}
1002+
*/
1003+
function isValidMap (map) {
1004+
return Array.isArray(map) || isObject(map)
1005+
}
1006+
9681007
/**
9691008
* Return a function expect two param contains namespace and map. it will normalize the namespace and then the param's function will handle the new namespace and the map.
9701009
* @param {Function} fn
@@ -1000,7 +1039,7 @@ function getModuleByNamespace (store, helper, namespace) {
10001039
var index = {
10011040
Store: Store,
10021041
install: install,
1003-
version: '3.1.1',
1042+
version: '3.1.2',
10041043
mapState: mapState,
10051044
mapMutations: mapMutations,
10061045
mapGetters: mapGetters,

Diff for: dist/vuex.esm.browser.js

+62-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vuex v3.1.1
2+
* vuex v3.1.2
33
* (c) 2019 Evan You
44
* @license MIT
55
*/
@@ -316,6 +316,7 @@ class Store {
316316
this._modulesNamespaceMap = Object.create(null);
317317
this._subscribers = [];
318318
this._watcherVM = new Vue();
319+
this._makeLocalGettersCache = Object.create(null);
319320

320321
// bind commit and dispatch to self
321322
const store = this;
@@ -532,12 +533,14 @@ function resetStoreVM (store, state, hot) {
532533

533534
// bind store public getters
534535
store.getters = {};
536+
// reset local getters cache
537+
store._makeLocalGettersCache = Object.create(null);
535538
const wrappedGetters = store._wrappedGetters;
536539
const computed = {};
537540
forEachValue(wrappedGetters, (fn, key) => {
538541
// use computed to leverage its lazy-caching mechanism
539542
// direct inline function use will lead to closure preserving oldVm.
540-
// using partial to return function with only arguments preserved in closure enviroment.
543+
// using partial to return function with only arguments preserved in closure environment.
541544
computed[key] = partial(fn, store);
542545
Object.defineProperty(store.getters, key, {
543546
get: () => store._vm[key],
@@ -581,6 +584,9 @@ function installModule (store, rootState, path, module, hot) {
581584

582585
// register in namespace map
583586
if (module.namespaced) {
587+
if (store._modulesNamespaceMap[namespace] && "development" !== 'production') {
588+
console.error(`[vuex] duplicate namespace ${namespace} for the namespaced module ${path.join('/')}`);
589+
}
584590
store._modulesNamespaceMap[namespace] = module;
585591
}
586592

@@ -589,6 +595,13 @@ function installModule (store, rootState, path, module, hot) {
589595
const parentState = getNestedState(rootState, path.slice(0, -1));
590596
const moduleName = path[path.length - 1];
591597
store._withCommit(() => {
598+
{
599+
if (moduleName in parentState) {
600+
console.warn(
601+
`[vuex] state field "${moduleName}" was overridden by a module with the same name at "${path.join('.')}"`
602+
);
603+
}
604+
}
592605
Vue.set(parentState, moduleName, module.state);
593606
});
594607
}
@@ -674,26 +687,28 @@ function makeLocalContext (store, namespace, path) {
674687
}
675688

676689
function makeLocalGetters (store, namespace) {
677-
const gettersProxy = {};
678-
679-
const splitPos = namespace.length;
680-
Object.keys(store.getters).forEach(type => {
681-
// skip if the target getter is not match this namespace
682-
if (type.slice(0, splitPos) !== namespace) return
683-
684-
// extract local getter type
685-
const localType = type.slice(splitPos);
686-
687-
// Add a port to the getters proxy.
688-
// Define as getter property because
689-
// we do not want to evaluate the getters in this time.
690-
Object.defineProperty(gettersProxy, localType, {
691-
get: () => store.getters[type],
692-
enumerable: true
690+
if (!store._makeLocalGettersCache[namespace]) {
691+
const gettersProxy = {};
692+
const splitPos = namespace.length;
693+
Object.keys(store.getters).forEach(type => {
694+
// skip if the target getter is not match this namespace
695+
if (type.slice(0, splitPos) !== namespace) return
696+
697+
// extract local getter type
698+
const localType = type.slice(splitPos);
699+
700+
// Add a port to the getters proxy.
701+
// Define as getter property because
702+
// we do not want to evaluate the getters in this time.
703+
Object.defineProperty(gettersProxy, localType, {
704+
get: () => store.getters[type],
705+
enumerable: true
706+
});
693707
});
694-
});
708+
store._makeLocalGettersCache[namespace] = gettersProxy;
709+
}
695710

696-
return gettersProxy
711+
return store._makeLocalGettersCache[namespace]
697712
}
698713

699714
function registerMutation (store, type, handler, local) {
@@ -705,15 +720,15 @@ function registerMutation (store, type, handler, local) {
705720

706721
function registerAction (store, type, handler, local) {
707722
const entry = store._actions[type] || (store._actions[type] = []);
708-
entry.push(function wrappedActionHandler (payload, cb) {
723+
entry.push(function wrappedActionHandler (payload) {
709724
let res = handler.call(store, {
710725
dispatch: local.dispatch,
711726
commit: local.commit,
712727
getters: local.getters,
713728
state: local.state,
714729
rootGetters: store.getters,
715730
rootState: store.state
716-
}, payload, cb);
731+
}, payload);
717732
if (!isPromise(res)) {
718733
res = Promise.resolve(res);
719734
}
@@ -794,6 +809,9 @@ function install (_Vue) {
794809
*/
795810
const mapState = normalizeNamespace((namespace, states) => {
796811
const res = {};
812+
if (!isValidMap(states)) {
813+
console.error('[vuex] mapState: mapper parameter must be either an Array or an Object');
814+
}
797815
normalizeMap(states).forEach(({ key, val }) => {
798816
res[key] = function mappedState () {
799817
let state = this.$store.state;
@@ -824,6 +842,9 @@ const mapState = normalizeNamespace((namespace, states) => {
824842
*/
825843
const mapMutations = normalizeNamespace((namespace, mutations) => {
826844
const res = {};
845+
if (!isValidMap(mutations)) {
846+
console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object');
847+
}
827848
normalizeMap(mutations).forEach(({ key, val }) => {
828849
res[key] = function mappedMutation (...args) {
829850
// Get the commit method from store
@@ -851,6 +872,9 @@ const mapMutations = normalizeNamespace((namespace, mutations) => {
851872
*/
852873
const mapGetters = normalizeNamespace((namespace, getters) => {
853874
const res = {};
875+
if (!isValidMap(getters)) {
876+
console.error('[vuex] mapGetters: mapper parameter must be either an Array or an Object');
877+
}
854878
normalizeMap(getters).forEach(({ key, val }) => {
855879
// The namespace has been mutated by normalizeNamespace
856880
val = namespace + val;
@@ -878,6 +902,9 @@ const mapGetters = normalizeNamespace((namespace, getters) => {
878902
*/
879903
const mapActions = normalizeNamespace((namespace, actions) => {
880904
const res = {};
905+
if (!isValidMap(actions)) {
906+
console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object');
907+
}
881908
normalizeMap(actions).forEach(({ key, val }) => {
882909
res[key] = function mappedAction (...args) {
883910
// get dispatch function from store
@@ -917,11 +944,23 @@ const createNamespacedHelpers = (namespace) => ({
917944
* @return {Object}
918945
*/
919946
function normalizeMap (map) {
947+
if (!isValidMap(map)) {
948+
return []
949+
}
920950
return Array.isArray(map)
921951
? map.map(key => ({ key, val: key }))
922952
: Object.keys(map).map(key => ({ key, val: map[key] }))
923953
}
924954

955+
/**
956+
* Validate whether given map is valid or not
957+
* @param {*} map
958+
* @return {Boolean}
959+
*/
960+
function isValidMap (map) {
961+
return Array.isArray(map) || isObject(map)
962+
}
963+
925964
/**
926965
* Return a function expect two param contains namespace and map. it will normalize the namespace and then the param's function will handle the new namespace and the map.
927966
* @param {Function} fn
@@ -957,7 +996,7 @@ function getModuleByNamespace (store, helper, namespace) {
957996
var index_esm = {
958997
Store,
959998
install,
960-
version: '3.1.1',
999+
version: '3.1.2',
9611000
mapState,
9621001
mapMutations,
9631002
mapGetters,

0 commit comments

Comments
 (0)