Skip to content

Commit 8e9b164

Browse files
feat(overmind): return transition object instead of string
1 parent aa2ccf8 commit 8e9b164

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/node_modules/overmind/src/statemachine.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ describe('Statemachine', () => {
184184

185185
const state = statemachine<States>({
186186
FOO: ['BAR'],
187-
BAR: () => 'FOO'
187+
BAR: () => ({ current: 'FOO' })
188188
}).create({
189189
current: 'FOO'
190190
})

packages/node_modules/overmind/src/statemachine.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import isPlainObject from 'is-plain-obj'
12
import { PATH, PROXY_TREE, VALUE } from 'proxy-state-tree'
23

34
import { deepCopy } from './utils'
@@ -10,7 +11,7 @@ type TStates = {
1011
}
1112

1213
export type StatemachineTransitions<States extends TStates, BaseState extends IState> = {
13-
[State in States["current"]]: Array<States["current"]> | ((payload: Omit<States extends { current: State } ? States & Partial<BaseState> : never, 'current'>, state: Statemachine<States, BaseState>) => States["current"] | Array<States["current"]> | boolean)
14+
[State in States["current"]]: Array<States["current"]> | ((payload: Omit<States extends { current: State } ? States & Partial<BaseState> : never, 'current'>, state: Statemachine<States, BaseState>) => States | Array<States["current"]> | boolean)
1415
}
1516

1617
export interface MachineMethods<States extends TStates, Base extends IState> {
@@ -96,9 +97,9 @@ export class StateMachine<Base extends IState, States extends TStates> {
9697
}
9798

9899

99-
if (typeof dynamicResult === 'string') {
100-
this[VALUE][CURRENT_DYNAMIC_TRANSITION] = [dynamicResult]
101-
return this.transition({ current: dynamicResult })
100+
if (isPlainObject(dynamicResult)) {
101+
this[VALUE][CURRENT_DYNAMIC_TRANSITION] = [dynamicResult.current]
102+
return this.transition(dynamicResult)
102103
}
103104

104105
if (dynamicResult === true) {

0 commit comments

Comments
 (0)