@@ -187,7 +187,7 @@ const hotReloadingCache = {}
187187export class Overmind < ThisConfig extends IConfiguration >
188188 implements IConfiguration {
189189 private proxyStateTree : ProxyStateTree < object >
190- private actionReferences : Function [ ] = [ ]
190+ private actionReferences : { [ path : string ] : Function } = { }
191191 private nextExecutionId : number = 0
192192 private mode : DefaultMode | TestMode | SSRMode
193193 private reydrateMutationsForHotReloading : IMutation [ ] = [ ]
@@ -433,7 +433,7 @@ export class Overmind<ThisConfig extends IConfiguration>
433433 const execution = {
434434 [ EXECUTION ] : true ,
435435 namespacePath,
436- actionId : this . actionReferences . indexOf ( action ) ,
436+ actionId : name ,
437437 executionId : this . nextExecutionId ++ ,
438438 actionName : name ,
439439 operatorId : 0 ,
@@ -519,9 +519,10 @@ export class Overmind<ThisConfig extends IConfiguration>
519519 private addExecutionMutation ( mutation : IMutation ) {
520520 ; ( ( this as unknown ) as OvermindMock < Config > ) . mutations . push ( mutation )
521521 }
522- private createAction ( name , action ) {
523- this . actionReferences . push ( action )
522+ private createAction ( name , originalAction ) {
523+ this . actionReferences [ name ] = originalAction
524524 const actionFunc = ( value ?, boundExecution ?: Execution ) => {
525+ const action = this . actionReferences [ name ]
525526 // Developer might unintentionally pass more arguments, so have to ensure
526527 // that it is an actual execution
527528 boundExecution =
@@ -882,6 +883,36 @@ export class Overmind<ThisConfig extends IConfiguration>
882883 } )
883884 } , { } ) as any
884885 }
886+ /*
887+ Related to hot reloading we update the existing action references and add any new
888+ actions.
889+ */
890+ private updateActions ( actions : any = { } , path : string [ ] = [ ] ) {
891+ Object . keys ( actions ) . forEach ( ( name ) => {
892+ if ( typeof actions [ name ] === 'function' ) {
893+ const actionName = path . concat ( name ) . join ( '.' )
894+ if ( this . actionReferences [ actionName ] ) {
895+ this . actionReferences [ actionName ] = actions [ name ]
896+ } else {
897+ const target = path . reduce ( ( aggr , key ) => {
898+ if ( ! aggr [ key ] ) {
899+ aggr [ key ] = { }
900+ }
901+
902+ return aggr [ key ]
903+ } , this . actions )
904+ target [ name ] = this . createAction (
905+ actionName ,
906+ actions [ name ]
907+ ) as any
908+
909+ target [ name ] . displayName = path . concat ( name ) . join ( '.' )
910+ }
911+ } else {
912+ this . updateActions ( actions [ name ] , path . concat ( name ) )
913+ }
914+ } , { } ) as any
915+ }
885916 getTrackStateTree ( ) : ITrackStateTree < any > {
886917 return this . proxyStateTree . getTrackStateTree ( )
887918 }
@@ -949,7 +980,8 @@ export class Overmind<ThisConfig extends IConfiguration>
949980 }
950981 reconfigure ( configuration : IConfiguration ) {
951982 const changeMutations = getChangeMutations ( this . originalConfiguration . state , configuration . state || { } )
952- this . actions = this . getActions ( configuration . actions )
983+
984+ this . updateActions ( configuration . actions )
953985 this . effects = configuration . effects || { }
954986
955987 const mutationTree = this . proxyStateTree . getMutationTree ( )
0 commit comments