@@ -7,9 +7,11 @@ let Vue // bind on install
77
88export class Store {
99 constructor ( options = { } ) {
10- assert ( Vue , `must call Vue.use(Vuex) before creating a store instance.` )
11- assert ( typeof Promise !== 'undefined' , `vuex requires a Promise polyfill in this browser.` )
12- assert ( this instanceof Store , `Store must be called with the new operator.` )
10+ if ( process . env . NODE_ENV !== 'production' ) {
11+ assert ( Vue , `must call Vue.use(Vuex) before creating a store instance.` )
12+ assert ( typeof Promise !== 'undefined' , `vuex requires a Promise polyfill in this browser.` )
13+ assert ( this instanceof Store , `Store must be called with the new operator.` )
14+ }
1315
1416 const {
1517 plugins = [ ] ,
@@ -64,7 +66,9 @@ export class Store {
6466 }
6567
6668 set state ( v ) {
67- assert ( false , `Use store.replaceState() to explicit replace store state.` )
69+ if ( process . env . NODE_ENV !== 'production' ) {
70+ assert ( false , `Use store.replaceState() to explicit replace store state.` )
71+ }
6872 }
6973
7074 commit ( _type , _payload , _options ) {
@@ -77,7 +81,7 @@ export class Store {
7781
7882 const mutation = { type, payload }
7983 const entry = this . _mutations [ type ]
80- if ( ! entry ) {
84+ if ( process . env . NODE_ENV !== 'production' && ! entry ) {
8185 console . error ( `[vuex] unknown mutation type: ${ type } ` )
8286 return
8387 }
@@ -88,7 +92,10 @@ export class Store {
8892 } )
8993 this . _subscribers . forEach ( sub => sub ( mutation , this . state ) )
9094
91- if ( options && options . silent ) {
95+ if (
96+ process . env . NODE_ENV !== 'production' &&
97+ options && options . silent
98+ ) {
9299 console . warn (
93100 `[vuex] mutation type: ${ type } . Silent option has been removed. ` +
94101 'Use the filter functionality in the vue-devtools'
@@ -104,7 +111,7 @@ export class Store {
104111 } = unifyObjectStyle ( _type , _payload )
105112
106113 const entry = this . _actions [ type ]
107- if ( ! entry ) {
114+ if ( process . env . NODE_ENV !== 'production' && ! entry ) {
108115 console . error ( `[vuex] unknown action type: ${ type } ` )
109116 return
110117 }
@@ -127,7 +134,9 @@ export class Store {
127134 }
128135
129136 watch ( getter , cb , options ) {
130- assert ( typeof getter === 'function' , `store.watch only accepts a function.` )
137+ if ( process . env . NODE_ENV !== 'production' ) {
138+ assert ( typeof getter === 'function' , `store.watch only accepts a function.` )
139+ }
131140 return this . _watcherVM . $watch ( ( ) => getter ( this . state , this . getters ) , cb , options )
132141 }
133142
@@ -139,8 +148,11 @@ export class Store {
139148
140149 registerModule ( path , rawModule ) {
141150 if ( typeof path === 'string' ) path = [ path ]
142- assert ( Array . isArray ( path ) , `module path must be a string or an Array.` )
143- assert ( path . length > 0 , 'cannot register the root module by using registerModule.' )
151+
152+ if ( process . env . NODE_ENV !== 'production' ) {
153+ assert ( Array . isArray ( path ) , `module path must be a string or an Array.` )
154+ assert ( path . length > 0 , 'cannot register the root module by using registerModule.' )
155+ }
144156
145157 this . _modules . register ( path , rawModule )
146158 installModule ( this , this . state , path , this . _modules . get ( path ) )
@@ -150,7 +162,11 @@ export class Store {
150162
151163 unregisterModule ( path ) {
152164 if ( typeof path === 'string' ) path = [ path ]
153- assert ( Array . isArray ( path ) , `module path must be a string or an Array.` )
165+
166+ if ( process . env . NODE_ENV !== 'production' ) {
167+ assert ( Array . isArray ( path ) , `module path must be a string or an Array.` )
168+ }
169+
154170 this . _modules . unregister ( path )
155171 this . _withCommit ( ( ) => {
156172 const parentState = getNestedState ( this . state , path . slice ( 0 , - 1 ) )
@@ -285,7 +301,7 @@ function makeLocalContext (store, namespace, path) {
285301
286302 if ( ! options || ! options . root ) {
287303 type = namespace + type
288- if ( ! store . _actions [ type ] ) {
304+ if ( process . env . NODE_ENV !== 'production' && ! store . _actions [ type ] ) {
289305 console . error ( `[vuex] unknown local action type: ${ args . type } , global type: ${ type } ` )
290306 return
291307 }
@@ -301,7 +317,7 @@ function makeLocalContext (store, namespace, path) {
301317
302318 if ( ! options || ! options . root ) {
303319 type = namespace + type
304- if ( ! store . _mutations [ type ] ) {
320+ if ( process . env . NODE_ENV !== 'production' && ! store . _mutations [ type ] ) {
305321 console . error ( `[vuex] unknown local mutation type: ${ args . type } , global type: ${ type } ` )
306322 return
307323 }
@@ -383,7 +399,7 @@ function registerAction (store, type, handler, local) {
383399}
384400
385401function registerGetter ( store , type , rawGetter , local ) {
386- if ( store . _wrappedGetters [ type ] ) {
402+ if ( process . env . NODE_ENV !== 'production' && store . _wrappedGetters [ type ] ) {
387403 console . error ( `[vuex] duplicate getter key: ${ type } ` )
388404 return
389405 }
@@ -399,7 +415,9 @@ function registerGetter (store, type, rawGetter, local) {
399415
400416function enableStrictMode ( store ) {
401417 store . _vm . $watch ( function ( ) { return this . _data . $$state } , ( ) => {
402- assert ( store . _committing , `Do not mutate vuex store state outside mutation handlers.` )
418+ if ( process . env . NODE_ENV !== 'production' ) {
419+ assert ( store . _committing , `Do not mutate vuex store state outside mutation handlers.` )
420+ }
403421 } , { deep : true , sync : true } )
404422}
405423
@@ -416,13 +434,15 @@ function unifyObjectStyle (type, payload, options) {
416434 type = type . type
417435 }
418436
419- assert ( typeof type === 'string' , `Expects string as the type, but found ${ typeof type } .` )
437+ if ( process . env . NODE_ENV !== 'production' ) {
438+ assert ( typeof type === 'string' , `Expects string as the type, but found ${ typeof type } .` )
439+ }
420440
421441 return { type, payload, options }
422442}
423443
424444export function install ( _Vue ) {
425- if ( Vue ) {
445+ if ( process . env . NODE_ENV !== 'production' && Vue ) {
426446 console . error (
427447 '[vuex] already installed. Vue.use(Vuex) should be called only once.'
428448 )
0 commit comments