@@ -59,7 +59,7 @@ import {
5959 getActionPaths ,
6060 getFunctionName ,
6161 isPromise ,
62- mergeState ,
62+ runMutation ,
6363 processState ,
6464} from './utils'
6565
@@ -189,7 +189,7 @@ export class Overmind<ThisConfig extends IConfiguration>
189189 private actionReferences : Function [ ] = [ ]
190190 private nextExecutionId : number = 0
191191 private mode : DefaultMode | TestMode | SSRMode
192- private originalConfiguration
192+ private reydrateMutationsForHotReloading : IMutation [ ] = [ ]
193193 initialized : Promise < any >
194194 eventHub : EventEmitter < Events >
195195 devtools : Devtools
@@ -238,8 +238,6 @@ export class Overmind<ThisConfig extends IConfiguration>
238238 eventHub ,
239239 mode . mode === MODE_SSR ? false : process . env . NODE_ENV === 'development'
240240 )
241-
242- this . originalConfiguration = configuration
243241 this . state = proxyStateTree . state
244242 this . effects = configuration . effects || { }
245243 this . proxyStateTree = proxyStateTree
@@ -324,6 +322,11 @@ export class Overmind<ThisConfig extends IConfiguration>
324322 nextTick = setTimeout ( flushTree , 0 )
325323 } )
326324 } else if ( mode . mode === MODE_DEFAULT || mode . mode === MODE_TEST ) {
325+ if ( process . env . NODE_ENV === 'test' || ( this . devtools && options . hotReloading !== false ) ) {
326+ eventHub . on ( EventType . MUTATIONS , ( execution ) => {
327+ this . reydrateMutationsForHotReloading = this . reydrateMutationsForHotReloading . concat ( execution . mutations )
328+ } )
329+ }
327330 eventHub . on ( EventType . OPERATOR_ASYNC , ( execution ) => {
328331 const flushData = execution . flush ( true )
329332 if ( this . devtools && flushData . mutations . length ) {
@@ -942,21 +945,22 @@ export class Overmind<ThisConfig extends IConfiguration>
942945 return this . proxyStateTree . onFlush ( cb )
943946 }
944947 reconfigure ( configuration : IConfiguration ) {
945- const mergedConfiguration = {
946- ...configuration ,
947- state : mergeState (
948- this . originalConfiguration . state ,
949- this . state ,
950- configuration . state
951- ) ,
952- }
953948 const proxyStateTree = this . proxyStateTree as any
954- this . originalConfiguration . state = configuration . state
955- this . proxyStateTree . sourceState = this . getState ( mergedConfiguration )
949+ this . proxyStateTree . sourceState = this . getState ( configuration )
956950 proxyStateTree . createTrackStateProxifier ( )
957951 this . state = this . proxyStateTree . state as any
958- this . actions = this . getActions ( mergedConfiguration . actions )
959- this . effects = mergedConfiguration . effects || { }
952+ this . actions = this . getActions ( configuration . actions )
953+ this . effects = configuration . effects || { }
954+
955+ this . reydrateMutationsForHotReloading . forEach ( ( mutation ) => {
956+ try {
957+ runMutation ( this . state , mutation )
958+ } catch ( error ) {
959+ // No worries, structure changed and we do not want to mutate anyways
960+ }
961+ } )
962+
963+ this . reydrateMutationsForHotReloading . length = 0
960964
961965 this . proxyStateTree . forceFlush ( )
962966
0 commit comments