Skip to content

Commit 1f4a374

Browse files
fix(overmind): return instance on transition to handle typing
1 parent be84911 commit 1f4a374

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe('Statemachine', () => {
208208
FOO: ['BAR'],
209209
BAR: ['FOO']
210210
}, {
211-
state: 'FOO'
211+
state: 'FOO',
212212
})
213213
const transition: Action = async ({ state }) => {
214214
if (state.transition('BAR')) {
@@ -224,6 +224,8 @@ describe('Statemachine', () => {
224224
}
225225
}
226226

227+
228+
227229
const config = {
228230
state,
229231
actions: {

packages/node_modules/overmind/src/statemachine.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ export type StatemachineTransitions<States extends TStates> = {
1212

1313
export interface MachineMethods<States extends TStates> {
1414
matches<T extends States["state"]>(state: T): this is Statemachine<States, States extends {
15-
state: T;
15+
state: T
1616
} ? States : never>;
17-
transition<State extends States["state"]>(
18-
state: State,
19-
): this is Statemachine<States, States extends {
20-
state: State
17+
transition<T extends States["state"]>(
18+
state: T,
19+
): undefined | Statemachine<States, States extends {
20+
state: T
2121
} ? States : never>
2222
}
2323

@@ -41,11 +41,10 @@ class StateMachine<States extends TStates, State extends TStates = States> {
4141
tree.enableMutations()
4242
this.state = state
4343
Promise.resolve().then(() => tree.blockMutations())
44-
return true
44+
return this
4545
} else if (process.env.NODE_ENV === 'development') {
4646
console.warn(`Overmind Statemachine - You tried to transition into "${state}", but it is not a valid transition. The valid transitions are ${JSON.stringify(transitions[this.state])}`)
4747
}
48-
return false
4948
}
5049
matches(state) {
5150
if (state === this.state) {

0 commit comments

Comments
 (0)