@@ -87,9 +87,9 @@ class Store {
87
87
this . _middlewares . forEach ( m => {
88
88
if ( m . onMutation ) {
89
89
if ( m . snapshot ) {
90
- m . onMutation ( { type, payload : clonedPayload } , snapshot , prevSnapshot )
90
+ m . onMutation ( { type, payload : clonedPayload } , snapshot , prevSnapshot , this )
91
91
} else {
92
- m . onMutation ( { type, payload } , state )
92
+ m . onMutation ( { type, payload } , state , this )
93
93
}
94
94
}
95
95
} )
@@ -129,18 +129,6 @@ class Store {
129
129
this . _setupModuleMutations ( modules || this . _modules )
130
130
}
131
131
132
- /**
133
- * Replace entire state tree.
134
- */
135
-
136
- replaceState ( newState ) {
137
- const state = this . _vm . _data
138
- const clone = deepClone ( newState )
139
- Object . keys ( clone ) . forEach ( key => {
140
- state [ key ] = clone [ key ]
141
- } )
142
- }
143
-
144
132
/**
145
133
* Attach sub state tree of each module to the root tree.
146
134
*
@@ -151,7 +139,7 @@ class Store {
151
139
_setupModuleState ( state , modules ) {
152
140
const { setPath } = Vue . parsers . path
153
141
Object . keys ( modules ) . forEach ( key => {
154
- setPath ( state , key , modules [ key ] . state )
142
+ setPath ( state , key , modules [ key ] . state || { } )
155
143
} )
156
144
}
157
145
@@ -168,6 +156,7 @@ class Store {
168
156
const allMutations = [ this . _rootMutations ]
169
157
Object . keys ( modules ) . forEach ( key => {
170
158
const module = modules [ key ]
159
+ if ( ! module || ! module . mutations ) return
171
160
// bind mutations to sub state tree
172
161
const mutations = { }
173
162
Object . keys ( module . mutations ) . forEach ( name => {
@@ -234,7 +223,7 @@ class Store {
234
223
// call init hooks
235
224
this . _middlewares . forEach ( m => {
236
225
if ( m . onInit ) {
237
- m . onInit ( m . snapshot ? initialSnapshot : state )
226
+ m . onInit ( m . snapshot ? initialSnapshot : state , this )
238
227
}
239
228
} )
240
229
}
0 commit comments