1
1
/**
2
- * vuex v2.4.0
2
+ * vuex v2.4.1
3
3
* (c) 2017 Evan You
4
4
* @license MIT
5
5
*/
@@ -105,7 +105,7 @@ var Module = function Module (rawModule, runtime) {
105
105
this . state = ( typeof rawState === 'function' ? rawState ( ) : rawState ) || { } ;
106
106
} ;
107
107
108
- var prototypeAccessors$1 = { namespaced : { } } ;
108
+ var prototypeAccessors$1 = { namespaced : { configurable : true } } ;
109
109
110
110
prototypeAccessors$1 . namespaced . get = function ( ) {
111
111
return ! ! this . _rawModule . namespaced
@@ -273,6 +273,13 @@ var Store = function Store (options) {
273
273
var this$1 = this ;
274
274
if ( options === void 0 ) options = { } ;
275
275
276
+ // Auto install if it is not done yet and `window` has `Vue`.
277
+ // To allow users to avoid auto-installation in some cases,
278
+ // this code should be placed here. See #731
279
+ if ( ! Vue && typeof window !== 'undefined' && window . Vue ) {
280
+ install ( window . Vue ) ;
281
+ }
282
+
276
283
if ( process . env . NODE_ENV !== 'production' ) {
277
284
assert ( Vue , "must call Vue.use(Vuex) before creating a store instance." ) ;
278
285
assert ( typeof Promise !== 'undefined' , "vuex requires a Promise polyfill in this browser." ) ;
@@ -329,7 +336,7 @@ var Store = function Store (options) {
329
336
}
330
337
} ;
331
338
332
- var prototypeAccessors = { state : { } } ;
339
+ var prototypeAccessors = { state : { configurable : true } } ;
333
340
334
341
prototypeAccessors . state . get = function ( ) {
335
342
return this . _vm . _data . $$state
@@ -727,7 +734,7 @@ function unifyObjectStyle (type, payload, options) {
727
734
}
728
735
729
736
function install ( _Vue ) {
730
- if ( Vue ) {
737
+ if ( Vue && _Vue === Vue ) {
731
738
if ( process . env . NODE_ENV !== 'production' ) {
732
739
console . error (
733
740
'[vuex] already installed. Vue.use(Vuex) should be called only once.'
@@ -739,11 +746,6 @@ function install (_Vue) {
739
746
applyMixin ( Vue ) ;
740
747
}
741
748
742
- // auto install in dist mode
743
- if ( typeof window !== 'undefined' && window . Vue ) {
744
- install ( window . Vue ) ;
745
- }
746
-
747
749
var mapState = normalizeNamespace ( function ( namespace , states ) {
748
750
var res = { } ;
749
751
normalizeMap ( states ) . forEach ( function ( ref ) {
@@ -777,15 +779,21 @@ var mapMutations = normalizeNamespace(function (namespace, mutations) {
777
779
var key = ref . key ;
778
780
var val = ref . val ;
779
781
780
- val = namespace + val ;
781
782
res [ key ] = function mappedMutation ( ) {
782
783
var args = [ ] , len = arguments . length ;
783
784
while ( len -- ) args [ len ] = arguments [ len ] ;
784
785
785
- if ( namespace && ! getModuleByNamespace ( this . $store , 'mapMutations' , namespace ) ) {
786
- return
786
+ var commit = this . $store . commit ;
787
+ if ( namespace ) {
788
+ var module = getModuleByNamespace ( this . $store , 'mapMutations' , namespace ) ;
789
+ if ( ! module ) {
790
+ return
791
+ }
792
+ commit = module . context . commit ;
787
793
}
788
- return this . $store . commit . apply ( this . $store , [ val ] . concat ( args ) )
794
+ return typeof val === 'function'
795
+ ? val . apply ( this , [ commit ] . concat ( args ) )
796
+ : commit . apply ( this . $store , [ val ] . concat ( args ) )
789
797
} ;
790
798
} ) ;
791
799
return res
@@ -820,15 +828,21 @@ var mapActions = normalizeNamespace(function (namespace, actions) {
820
828
var key = ref . key ;
821
829
var val = ref . val ;
822
830
823
- val = namespace + val ;
824
831
res [ key ] = function mappedAction ( ) {
825
832
var args = [ ] , len = arguments . length ;
826
833
while ( len -- ) args [ len ] = arguments [ len ] ;
827
834
828
- if ( namespace && ! getModuleByNamespace ( this . $store , 'mapActions' , namespace ) ) {
829
- return
835
+ var dispatch = this . $store . dispatch ;
836
+ if ( namespace ) {
837
+ var module = getModuleByNamespace ( this . $store , 'mapActions' , namespace ) ;
838
+ if ( ! module ) {
839
+ return
840
+ }
841
+ dispatch = module . context . dispatch ;
830
842
}
831
- return this . $store . dispatch . apply ( this . $store , [ val ] . concat ( args ) )
843
+ return typeof val === 'function'
844
+ ? val . apply ( this , [ dispatch ] . concat ( args ) )
845
+ : dispatch . apply ( this . $store , [ val ] . concat ( args ) )
832
846
} ;
833
847
} ) ;
834
848
return res
@@ -870,12 +884,13 @@ function getModuleByNamespace (store, helper, namespace) {
870
884
var index_esm = {
871
885
Store : Store ,
872
886
install : install ,
873
- version : '2.4.0 ' ,
887
+ version : '2.4.1 ' ,
874
888
mapState : mapState ,
875
889
mapMutations : mapMutations ,
876
890
mapGetters : mapGetters ,
877
891
mapActions : mapActions ,
878
892
createNamespacedHelpers : createNamespacedHelpers
879
893
} ;
880
894
881
- export { Store , mapState , mapMutations , mapGetters , mapActions , createNamespacedHelpers } ; export default index_esm ;
895
+ export { Store , install , mapState , mapMutations , mapGetters , mapActions , createNamespacedHelpers } ;
896
+ export default index_esm ;
0 commit comments