@@ -7,9 +7,11 @@ let Vue // bind on install
7
7
8
8
export class Store {
9
9
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
+ }
13
15
14
16
const {
15
17
plugins = [ ] ,
@@ -64,7 +66,9 @@ export class Store {
64
66
}
65
67
66
68
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
+ }
68
72
}
69
73
70
74
commit ( _type , _payload , _options ) {
@@ -77,7 +81,7 @@ export class Store {
77
81
78
82
const mutation = { type, payload }
79
83
const entry = this . _mutations [ type ]
80
- if ( ! entry ) {
84
+ if ( process . env . NODE_ENV !== 'production' && ! entry ) {
81
85
console . error ( `[vuex] unknown mutation type: ${ type } ` )
82
86
return
83
87
}
@@ -88,7 +92,10 @@ export class Store {
88
92
} )
89
93
this . _subscribers . forEach ( sub => sub ( mutation , this . state ) )
90
94
91
- if ( options && options . silent ) {
95
+ if (
96
+ process . env . NODE_ENV !== 'production' &&
97
+ options && options . silent
98
+ ) {
92
99
console . warn (
93
100
`[vuex] mutation type: ${ type } . Silent option has been removed. ` +
94
101
'Use the filter functionality in the vue-devtools'
@@ -104,7 +111,7 @@ export class Store {
104
111
} = unifyObjectStyle ( _type , _payload )
105
112
106
113
const entry = this . _actions [ type ]
107
- if ( ! entry ) {
114
+ if ( process . env . NODE_ENV !== 'production' && ! entry ) {
108
115
console . error ( `[vuex] unknown action type: ${ type } ` )
109
116
return
110
117
}
@@ -127,7 +134,9 @@ export class Store {
127
134
}
128
135
129
136
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
+ }
131
140
return this . _watcherVM . $watch ( ( ) => getter ( this . state , this . getters ) , cb , options )
132
141
}
133
142
@@ -139,8 +148,11 @@ export class Store {
139
148
140
149
registerModule ( path , rawModule ) {
141
150
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
+ }
144
156
145
157
this . _modules . register ( path , rawModule )
146
158
installModule ( this , this . state , path , this . _modules . get ( path ) )
@@ -150,7 +162,11 @@ export class Store {
150
162
151
163
unregisterModule ( path ) {
152
164
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
+
154
170
this . _modules . unregister ( path )
155
171
this . _withCommit ( ( ) => {
156
172
const parentState = getNestedState ( this . state , path . slice ( 0 , - 1 ) )
@@ -285,7 +301,7 @@ function makeLocalContext (store, namespace, path) {
285
301
286
302
if ( ! options || ! options . root ) {
287
303
type = namespace + type
288
- if ( ! store . _actions [ type ] ) {
304
+ if ( process . env . NODE_ENV !== 'production' && ! store . _actions [ type ] ) {
289
305
console . error ( `[vuex] unknown local action type: ${ args . type } , global type: ${ type } ` )
290
306
return
291
307
}
@@ -301,7 +317,7 @@ function makeLocalContext (store, namespace, path) {
301
317
302
318
if ( ! options || ! options . root ) {
303
319
type = namespace + type
304
- if ( ! store . _mutations [ type ] ) {
320
+ if ( process . env . NODE_ENV !== 'production' && ! store . _mutations [ type ] ) {
305
321
console . error ( `[vuex] unknown local mutation type: ${ args . type } , global type: ${ type } ` )
306
322
return
307
323
}
@@ -383,7 +399,7 @@ function registerAction (store, type, handler, local) {
383
399
}
384
400
385
401
function registerGetter ( store , type , rawGetter , local ) {
386
- if ( store . _wrappedGetters [ type ] ) {
402
+ if ( process . env . NODE_ENV !== 'production' && store . _wrappedGetters [ type ] ) {
387
403
console . error ( `[vuex] duplicate getter key: ${ type } ` )
388
404
return
389
405
}
@@ -399,7 +415,9 @@ function registerGetter (store, type, rawGetter, local) {
399
415
400
416
function enableStrictMode ( store ) {
401
417
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
+ }
403
421
} , { deep : true , sync : true } )
404
422
}
405
423
@@ -416,13 +434,15 @@ function unifyObjectStyle (type, payload, options) {
416
434
type = type . type
417
435
}
418
436
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
+ }
420
440
421
441
return { type, payload, options }
422
442
}
423
443
424
444
export function install ( _Vue ) {
425
- if ( Vue ) {
445
+ if ( process . env . NODE_ENV !== 'production' && Vue ) {
426
446
console . error (
427
447
'[vuex] already installed. Vue.use(Vuex) should be called only once.'
428
448
)
0 commit comments