@@ -16,10 +16,9 @@ import {
1616 TConfig ,
1717 TDerive ,
1818 TOperator ,
19- TReaction ,
2019 TValueContext ,
2120 TOnInitialize ,
22- StateObject ,
21+ TStateObject ,
2322} from './types'
2423
2524export * from './types'
@@ -34,14 +33,12 @@ type TheConfig = IConfig & TConfig<{ actions: {} }>
3433
3534export type Action < Value = void > = TAction < TheConfig , Value >
3635
37- export type Derive < Parent extends StateObject , Value > = TDerive <
36+ export type Derive < Parent extends TStateObject , Value > = TDerive <
3837 TheConfig ,
3938 Parent ,
4039 Value
4140>
4241
43- export type Reaction = TReaction < TheConfig >
44-
4542export type OnInitialize = TOnInitialize < TheConfig >
4643
4744const isPlainObject = require ( 'is-plain-object' )
@@ -179,6 +176,7 @@ export class Overmind<Config extends Configuration> implements Configuration {
179176 operatorId : - 1 ,
180177 path : [ ] ,
181178 emit : this . eventHub . emit . bind ( this . eventHub ) ,
179+ send : this . devtools ? this . devtools . send . bind ( this . devtools ) : ( ) => { } ,
182180 }
183181 }
184182 private createContext ( value , execution , tree ) {
@@ -745,13 +743,27 @@ export function mutate<Input, Config extends Configuration = TheConfig>(
745743 if ( err ) next ( err )
746744 else {
747745 startDebugOperator ( 'mutate' , operation , context )
748- const mutationsTree = context . proxyStateTree . getMutationTree ( )
749- operation ( { ...context , state : mutationsTree . state } )
750- const newContext = createContext ( context , context . value )
751- context . execution . emit ( EventType . MUTATIONS , {
752- ...newContext . execution ,
753- mutations : mutationsTree . mutations ,
746+ const mutationTree = context . proxyStateTree . getMutationTree ( )
747+ if ( ! IS_PRODUCTION ) {
748+ mutationTree . onMutation ( ( mutation ) => {
749+ context . execution . emit ( EventType . MUTATIONS , {
750+ ...context . execution ,
751+ operatorId : context . execution . operatorId + 1 ,
752+ mutations : [ mutation ] ,
753+ } )
754+ } )
755+ }
756+ const maybePromise : any = operation ( {
757+ ...context ,
758+ state : mutationTree . state ,
754759 } )
760+ const newContext = createContext (
761+ context ,
762+ maybePromise instanceof Promise
763+ ? maybePromise . then ( ( ) => context . value )
764+ : context . value
765+ )
766+
755767 stopDebugOperator ( newContext )
756768 next ( null , newContext )
757769 }
0 commit comments