Skip to content

Commit 7f8e177

Browse files
fix(overmind): make operators also handle inline execution
1 parent 7168161 commit 7f8e177

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
EXECUTION,
5050
processState,
5151
isPromise,
52-
} from './utils'
52+
MODE_DEFAULT, MODE_TEST, MODE_SSR } from './utils'
5353
import {
5454
operatorStarted,
5555
operatorStopped,
@@ -59,10 +59,13 @@ import {
5959
createOperator,
6060
} from './operator'
6161

62+
6263
export * from './types'
6364

6465
export { createOperator, createMutationOperator }
6566

67+
export { MODE_DEFAULT, MODE_TEST, MODE_SSR } from './utils'
68+
6669
/** This type can be overwriten by app developers if they want to avoid
6770
* typing and then they can import `Action`, `Operation` etc. directly from
6871
* overmind.
@@ -82,10 +85,6 @@ export interface Derive<Parent extends IState, Value>
8285

8386
export interface OnInitialize extends IOnInitialize<Config> {}
8487

85-
export const MODE_DEFAULT = Symbol('MODE_DEFAULT')
86-
export const MODE_TEST = Symbol('MODE_TEST')
87-
export const MODE_SSR = Symbol('MODE_SSR')
88-
8988
export const json = (obj: any) =>
9089
deepCopy(obj && obj[IS_PROXY] ? obj[VALUE] : obj)
9190

@@ -516,11 +515,8 @@ export class Overmind<ThisConfig extends IConfiguration>
516515
action(
517516
null,
518517
{
518+
...this.createContext(execution, this.proxyStateTree),
519519
value,
520-
state: this.proxyStateTree.state,
521-
actions: this.actions,
522-
execution,
523-
effects: this.trackEffects(this.effects, execution),
524520
},
525521
(err, finalContext) => {
526522
execution.isRunning = false

packages/node_modules/overmind/src/operator.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import {
33
makeStringifySafeMutations,
44
createActionsProxy,
55
ORIGINAL_ACTIONS,
6-
} from './utils'
6+
MODE_TEST } from './utils'
77
import { EventType, Execution } from './internalTypes'
88
import { safeValue } from './Devtools'
99
import { IContext, IConfiguration, IOperator } from './types'
1010

11+
1112
export function operatorStarted(type, arg, context) {
1213
if (process.env.NODE_ENV === 'production') {
1314
return
@@ -86,6 +87,7 @@ export function createContext(context, value, path?) {
8687
path: path || context.execution.path,
8788
}
8889

90+
const mutationTrees: any[] = []
8991
return {
9092
...context,
9193
actions: createActionsProxy(
@@ -98,6 +100,25 @@ export function createContext(context, value, path?) {
98100
value,
99101
execution: newExecution,
100102
effects: context.execution.trackEffects(newExecution),
103+
flush: context.parentExecution
104+
? context.parentExecution.flush
105+
: (isAsync?: boolean) => {
106+
return this.proxyStateTree.flush(mutationTrees, isAsync)
107+
},
108+
getMutationTree: context.parentExecution
109+
? context.parentExecution.getMutationTree
110+
: () => {
111+
const mutationTree = this.proxyStateTree.getMutationTree()
112+
113+
mutationTrees.push(mutationTree)
114+
115+
if (this.mode.mode === MODE_TEST) {
116+
mutationTree.onMutation((mutation) => {
117+
this.addExecutionMutation(mutation)
118+
})
119+
}
120+
return mutationTree
121+
},
101122
}
102123
}
103124

packages/node_modules/overmind/src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export const IS_OPERATOR = Symbol('operator')
88
export const ORIGINAL_ACTIONS = Symbol('origina_actions')
99
export const EXECUTION = Symbol('execution')
1010

11+
export const MODE_DEFAULT = Symbol('MODE_DEFAULT')
12+
export const MODE_TEST = Symbol('MODE_TEST')
13+
export const MODE_SSR = Symbol('MODE_SSR')
14+
1115
export class MockedEventEmitter {
1216
emit() {}
1317
emitAsync() {}

0 commit comments

Comments
 (0)