@@ -6,17 +6,8 @@ let Vue // bind on install
6
6
7
7
class Store {
8
8
constructor ( options = { } ) {
9
- if ( ! Vue ) {
10
- throw new Error (
11
- '[vuex] must call Vue.use(Vuex) before creating a store instance.'
12
- )
13
- }
14
-
15
- if ( typeof Promise === 'undefined' ) {
16
- throw new Error (
17
- '[vuex] vuex requires a Promise polyfill in this browser.'
18
- )
19
- }
9
+ assert ( Vue , `must call Vue.use(Vuex) before creating a store instance.` )
10
+ assert ( typeof Promise !== 'undefined' , `vuex requires a Promise polyfill in this browser.` )
20
11
21
12
const {
22
13
state = { } ,
@@ -61,7 +52,7 @@ class Store {
61
52
}
62
53
63
54
set state ( v ) {
64
- throw new Error ( '[vuex] Use store.replaceState() to explicit replace store state.' )
55
+ assert ( false , ` Use store.replaceState() to explicit replace store state.` )
65
56
}
66
57
67
58
replaceState ( state ) {
@@ -72,9 +63,7 @@ class Store {
72
63
73
64
module ( path , module , hot ) {
74
65
if ( typeof path === 'string' ) path = [ path ]
75
- if ( ! Array . isArray ( path ) ) {
76
- throw new Error ( '[vuex] module path must be a string or an Array.' )
77
- }
66
+ assert ( Array . isArray ( path ) , `module path must be a string or an Array.` )
78
67
79
68
const isRoot = ! path . length
80
69
const {
@@ -170,7 +159,6 @@ class Store {
170
159
dispatch ( type , payload ) {
171
160
const entry = this . _actions [ type ]
172
161
if ( ! entry ) {
173
- debugger
174
162
console . error ( `[vuex] unknown action type: ${ type } ` )
175
163
return
176
164
}
@@ -192,6 +180,11 @@ class Store {
192
180
}
193
181
}
194
182
183
+ watch ( getter , cb , options ) {
184
+ assert ( typeof getter === 'function' , `store.watch only accepts a function.` )
185
+ return this . _vm . $watch ( ( ) => getter ( this . state ) , cb , options )
186
+ }
187
+
195
188
hotUpdate ( newOptions ) {
196
189
this . _actions = Object . create ( null )
197
190
this . _mutations = Object . create ( null )
@@ -227,6 +220,10 @@ class Store {
227
220
}
228
221
}
229
222
223
+ function assert ( condition , msg ) {
224
+ if ( ! condition ) throw new Error ( `[vuex] ${ msg } ` )
225
+ }
226
+
230
227
function initStoreState ( store , state , getters ) {
231
228
// bind getters
232
229
store . getters = { }
@@ -276,11 +273,7 @@ function extractModuleGetters (getters = {}, modules = {}, path = []) {
276
273
277
274
function enableStrictMode ( store ) {
278
275
store . _vm . $watch ( 'state' , ( ) => {
279
- if ( ! store . _committing ) {
280
- throw new Error (
281
- '[vuex] Do not mutate vuex store state outside mutation handlers.'
282
- )
283
- }
276
+ assert ( store . _committing , `Do not mutate vuex store state outside mutation handlers.` )
284
277
} , { deep : true , sync : true } )
285
278
}
286
279
0 commit comments