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
676689function 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
699714function registerMutation ( store , type , handler , local ) {
@@ -705,15 +720,15 @@ function registerMutation (store, type, handler, local) {
705720
706721function 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 */
795810const 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 */
825843const 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 */
852873const 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 */
879903const 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 */
919946function 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) {
957996var 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