Skip to content

Commit 93d3e4a

Browse files
fix(overmind): trigger statechart transition before action
1 parent 360ccb8 commit 93d3e4a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/node_modules/overmind/src/config/statecharts.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ export function statecharts<C extends IConfiguration, Charts extends Statecharts
339339
actionsTarget[ACTIONS][key](payload)
340340
}
341341

342-
transitions.forEach((transition, index) => {
342+
const actionsToRun = transitions.reduce((aggr, transition, index) => {
343343
const oldStatePath = stateTarget.states[index].slice()
344344

345345
if (transition === 'entry' || transition === 'exit') {
346346
newStates.push(oldStatePath)
347-
return
347+
return aggr
348348
}
349349

350350
const currentStatePath = stateTarget.states[index].slice()
@@ -406,13 +406,17 @@ export function statecharts<C extends IConfiguration, Charts extends Statecharts
406406

407407

408408
if (transition) {
409-
actionsTarget[ACTIONS][key](payload)
409+
return aggr.concat(() => actionsTarget[ACTIONS][key](payload))
410410
}
411-
})
411+
412+
return aggr
413+
}, [] as Function[])
412414

413415
// Actually change what has changed
414416
stateTarget.states = newStates
415417

418+
actionsToRun.forEach((action)=> action())
419+
416420
if (process.env.NODE_ENV === 'development' && currentInstance.devtools) {
417421
currentInstance.devtools.send({
418422
type: 'chart',

0 commit comments

Comments
 (0)