@@ -87,9 +87,9 @@ class Store {
8787 this . _middlewares . forEach ( m => {
8888 if ( m . onMutation ) {
8989 if ( m . snapshot ) {
90- m . onMutation ( { type, payload : clonedPayload } , snapshot , prevSnapshot )
90+ m . onMutation ( { type, payload : clonedPayload } , snapshot , prevSnapshot , this )
9191 } else {
92- m . onMutation ( { type, payload } , state )
92+ m . onMutation ( { type, payload } , state , this )
9393 }
9494 }
9595 } )
@@ -129,18 +129,6 @@ class Store {
129129 this . _setupModuleMutations ( modules || this . _modules )
130130 }
131131
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-
144132 /**
145133 * Attach sub state tree of each module to the root tree.
146134 *
@@ -151,7 +139,7 @@ class Store {
151139 _setupModuleState ( state , modules ) {
152140 const { setPath } = Vue . parsers . path
153141 Object . keys ( modules ) . forEach ( key => {
154- setPath ( state , key , modules [ key ] . state )
142+ setPath ( state , key , modules [ key ] . state || { } )
155143 } )
156144 }
157145
@@ -168,6 +156,7 @@ class Store {
168156 const allMutations = [ this . _rootMutations ]
169157 Object . keys ( modules ) . forEach ( key => {
170158 const module = modules [ key ]
159+ if ( ! module || ! module . mutations ) return
171160 // bind mutations to sub state tree
172161 const mutations = { }
173162 Object . keys ( module . mutations ) . forEach ( name => {
@@ -234,7 +223,7 @@ class Store {
234223 // call init hooks
235224 this . _middlewares . forEach ( m => {
236225 if ( m . onInit ) {
237- m . onInit ( m . snapshot ? initialSnapshot : state )
226+ m . onInit ( m . snapshot ? initialSnapshot : state , this )
238227 }
239228 } )
240229 }
0 commit comments