Skip to content

Commit

Permalink
feat(overmind): return transition object instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed Jan 23, 2021
1 parent 07c5f56 commit 413f64b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/node_modules/overmind/src/statemachine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('Statemachine', () => {

const state = statemachine<States>({
FOO: ['BAR'],
BAR: () => 'FOO'
BAR: () => ({ current: 'FOO' })
}).create({
current: 'FOO'
})
Expand Down
9 changes: 5 additions & 4 deletions packages/node_modules/overmind/src/statemachine.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isPlainObject from 'is-plain-obj'
import { PATH, PROXY_TREE, VALUE } from 'proxy-state-tree'

import { deepCopy } from './utils'
Expand All @@ -10,7 +11,7 @@ type TStates = {
}

export type StatemachineTransitions<States extends TStates, BaseState extends IState> = {
[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)
[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)
}

export interface MachineMethods<States extends TStates, Base extends IState> {
Expand Down Expand Up @@ -96,9 +97,9 @@ export class StateMachine<Base extends IState, States extends TStates> {
}


if (typeof dynamicResult === 'string') {
this[VALUE][CURRENT_DYNAMIC_TRANSITION] = [dynamicResult]
return this.transition({ current: dynamicResult })
if (isPlainObject(dynamicResult)) {
this[VALUE][CURRENT_DYNAMIC_TRANSITION] = [dynamicResult.current]
return this.transition(dynamicResult)
}

if (dynamicResult === true) {
Expand Down

0 comments on commit 413f64b

Please sign in to comment.