Skip to content

Commit b2d6a9c

Browse files
fix(overmind): ensure flushes are made from async actions in production
1 parent 8e7ba90 commit b2d6a9c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ export class Overmind<Config extends Configuration> implements BaseApp {
156156
} else {
157157
this.initialized = Promise.resolve(null)
158158
}
159+
160+
if (IS_PRODUCTION) {
161+
let nextTick
162+
const flushTree = () => proxyStateTree.flush()
163+
this.proxyStateTree.addMutationListener(() => {
164+
clearTimeout(nextTick)
165+
nextTick = setTimeout(flushTree, 0)
166+
})
167+
}
159168
}
160169
private createExecution(name, action) {
161170
return {
@@ -204,9 +213,7 @@ export class Overmind<Config extends Configuration> implements BaseApp {
204213
private createAction(name, action) {
205214
this.actionReferences.push(action)
206215
return (value?) => {
207-
if (IS_PRODUCTION) {
208-
return action(value)
209-
} else if (action[IS_PIPE]) {
216+
if (IS_PRODUCTION || action[IS_PIPE]) {
210217
return new Promise((resolve, reject) => {
211218
const execution = this.createExecution(name, action)
212219
this.eventHub.emit(EventType.ACTION_START, execution)

packages/node_modules/proxy-state-tree/src/proxify.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const isPlainObject = require('is-plain-object')
2-
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
32

43
export const IS_PROXY = Symbol('IS_PROXY')
54
export const PATH = Symbol('PATH')
@@ -30,7 +29,7 @@ function shouldTrackMutations(tree, path) {
3029
}
3130

3231
function ensureMutationTrackingIsEnabled(tree, path) {
33-
if (!tree.status.has(STATUS.TRACKING_MUTATIONS)) {
32+
if (tree.options.devmode && !tree.status.has(STATUS.TRACKING_MUTATIONS)) {
3433
throw new Error(
3534
`proxy-state-tree - You are mutating the path "${path}", but it is not allowed`
3635
)

0 commit comments

Comments
 (0)