Skip to content

Commit 9eb5ec9

Browse files
Merge branch 'next' of https://github.com/cerebral/overmind into next
2 parents 7bac53e + c725378 commit 9eb5ec9

File tree

10 files changed

+198
-141
lines changed

10 files changed

+198
-141
lines changed

packages/node_modules/overmind/src/config/statechart.test.ts renamed to packages/node_modules/overmind/src/config/statecharts.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IAction, createOvermind } from '../'
2-
import { Statechart, statechart } from './'
2+
import { Statechart, statecharts } from './'
33

44
describe('Statecharts', () => {
55
test('should wrap configs', () => {
@@ -13,7 +13,7 @@ describe('Statecharts', () => {
1313
foo: {},
1414
},
1515
}
16-
const instance = createOvermind(statechart(config, {
16+
const instance = createOvermind(statecharts(config, {
1717
id1: chart
1818
}))
1919

@@ -58,7 +58,7 @@ describe('Statecharts', () => {
5858
interface Action<Input = void, Output = void>
5959
extends IAction<typeof config, Input, Output> {}
6060

61-
const instance = createOvermind(statechart(config, {
61+
const instance = createOvermind(statecharts(config, {
6262
id1: chart
6363
}))
6464

@@ -110,7 +110,7 @@ describe('Statecharts', () => {
110110
interface Action<Input = void, Output = void>
111111
extends IAction<typeof config, Input, Output> {}
112112

113-
const instance = createOvermind(statechart(config, {
113+
const instance = createOvermind(statecharts(config, {
114114
id1: chart
115115
}))
116116

@@ -159,7 +159,7 @@ describe('Statecharts', () => {
159159
interface Action<Input = void, Output = void>
160160
extends IAction<typeof config, Input, Output> {}
161161

162-
const instance = createOvermind(statechart(config, {
162+
const instance = createOvermind(statecharts(config, {
163163
id1: chart
164164
}))
165165

@@ -227,7 +227,7 @@ describe('Statecharts', () => {
227227
interface Action<Input = void, Output = void>
228228
extends IAction<typeof config, Input, Output> {}
229229

230-
const instance = createOvermind(statechart(config, {
230+
const instance = createOvermind(statecharts(config, {
231231
id1: chart
232232
}))
233233

@@ -339,7 +339,7 @@ describe('Statecharts', () => {
339339
interface Action<Input = void, Output = void>
340340
extends IAction<typeof config, Input, Output> {}
341341

342-
const instance = createOvermind(statechart(config, {
342+
const instance = createOvermind(statecharts(config, {
343343
test: chart
344344
}))
345345

@@ -438,7 +438,7 @@ describe('Statecharts', () => {
438438
extends IAction<typeof config, Input, Output> {}
439439

440440
const instance = createOvermind(
441-
statechart(config, {chartA, chartB})
441+
statecharts(config, {chartA, chartB})
442442
)
443443

444444
expect(instance.state.states).toEqual([['chartA', 'bar'], ['chartB', 'foo']])
@@ -547,7 +547,7 @@ describe('Statecharts', () => {
547547
extends IAction<typeof config, Input, Output> {}
548548

549549
const instance = createOvermind(
550-
statechart(config, {parallelChartA, parallelChartB})
550+
statecharts(config, {parallelChartA, parallelChartB})
551551
)
552552

553553
expect(instance.state.states).toEqual([['parallelChartA', 'bar'], ['parallelChartB', 'foo', 'nestedChartB', 'foo']])
@@ -652,7 +652,7 @@ describe('Statecharts', () => {
652652
interface Action<Input = void, Output = void>
653653
extends IAction<typeof config, Input, Output> {}
654654

655-
const instance = createOvermind(statechart(config, {mainChart}))
655+
const instance = createOvermind(statecharts(config, {mainChart}))
656656

657657
expect(instance.state.states).toEqual([['mainChart', 'foo', 'chart', 'baz'], ['mainChart', 'foo', 'chartB', 'baz']])
658658
expect(instance.state.actions).toEqual({ increaseCount: true, changeToBar: true })

packages/node_modules/overmind/src/config/statechart.ts renamed to packages/node_modules/overmind/src/config/statecharts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ type Match<T extends Statecharts> = {
200200
}
201201
}
202202

203-
export function statechart<C extends IConfiguration, Charts extends Statecharts>(
203+
export function statecharts<C extends IConfiguration, Charts extends Statecharts>(
204204
config: C,
205205
charts: Charts
206206
): IConfig<{

packages/node_modules/overmind/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ export class Overmind<ThisConfig extends IConfiguration>
615615
error: error.message,
616616
})
617617
this.eventHub.emit(EventType.ACTION_END, execution)
618+
619+
throw error
618620
})
619621
} else {
620622
execution.isRunning = false

packages/overmind-website/examples/guide/statecharts/condition.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default (ts, view) =>
44
{
55
fileName: 'overmind/login/index.ts',
66
code: `
7-
import { Statechart, statechart } from 'overmind/config'
7+
import { Statechart, statecharts } from 'overmind/config'
88
import * as actions from './actions'
99
import { state } from './state'
1010
@@ -13,22 +13,20 @@ const config = {
1313
actions
1414
}
1515
16-
enum LoginState {
17-
LOGIN = 'LOGIN',
18-
AUTHENTICATING = 'AUTHENTICATING',
19-
AUTHENTICATED = 'AUTHENTICATED',
20-
ERROR = 'ERROR'
21-
}
22-
23-
const loginChart: Statechart<typeof config, LoginState> = {
24-
initial: LoginState.LOGIN,
16+
const loginChart: Statechart<typeof config, {
17+
LOGIN: void
18+
AUTHENTICATING: void
19+
AUTHENTICATED: void
20+
ERROR: void
21+
}> = {
22+
initial: 'LOGIN',
2523
states: {
26-
[LoginState.LOGIN]: {
24+
LOGIN: {
2725
on: {
2826
changeUsername: null,
2927
changePassword: null,
3028
login: {
31-
target: LoginState.AUTHENTICATING,
29+
target: 'AUTHENTICATING',
3230
condition: state => Boolean(state.username && state.password)
3331
}
3432
}
@@ -37,15 +35,17 @@ const loginChart: Statechart<typeof config, LoginState> = {
3735
}
3836
}
3937
40-
export default statechart(config, loginChart)
38+
export default statecharts(config, {
39+
login: loginChart
40+
})
4141
`,
4242
},
4343
]
4444
: [
4545
{
4646
fileName: 'overmind/login/index.ts',
4747
code: `
48-
import { statechart } from 'overmind/config'
48+
import { statecharts } from 'overmind/config'
4949
import * as actions from './actions'
5050
import { state } from './state'
5151
@@ -71,7 +71,9 @@ const loginChart = {
7171
}
7272
}
7373
74-
export default statechart(config, loginChart)
74+
export default statecharts(config, {
75+
login: loginChart
76+
})
7577
`,
7678
},
7779
]

packages/overmind-website/examples/guide/statecharts/define.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default (ts, view) =>
44
{
55
fileName: 'overmind/login/index.ts',
66
code: `
7-
import { Statechart, statechart } from 'overmind/config'
7+
import { Statechart, statecharts } from 'overmind/config'
88
import * as actions from './actions'
99
import { state } from './state'
1010
@@ -13,51 +13,51 @@ const config = {
1313
actions
1414
}
1515
16-
enum LoginState {
17-
LOGIN = 'LOGIN',
18-
AUTHENTICATING = 'AUTHENTICATING',
19-
AUTHENTICATED = 'AUTHENTICATED',
20-
ERROR = 'ERROR'
21-
}
22-
23-
const loginChart: Statechart<typeof config, LoginState> = {
24-
initial: LoginState.LOGIN,
16+
const loginChart: Statechart<typeof config, {
17+
LOGIN: void
18+
AUTHENTICATING: void
19+
AUTHENTICATED: void
20+
ERROR: void
21+
}> = {
22+
initial: 'LOGIN',
2523
states: {
26-
[LoginState.LOGIN]: {
24+
LOGIN: {
2725
on: {
2826
changeUsername: null,
2927
changePassword: null,
30-
login: LoginState.AUTHENTICATING
28+
login: 'AUTHENTICATING'
3129
}
3230
},
33-
[LoginState.AUTHENTICATING]: {
31+
AUTHENTICATING: {
3432
on: {
35-
resolveUser: LoginState.AUTHENTICATED,
36-
rejectUser: LoginState.ERROR
33+
resolveUser: 'AUTHENTICATED',
34+
rejectUser: 'ERROR'
3735
}
3836
},
39-
[LoginState.AUTHENTICATED]: {
37+
AUTHENTICATED: {
4038
on: {
41-
logout: LoginState.LOGIN
39+
logout: 'LOGIN'
4240
}
4341
},
44-
[LoginState.ERROR]: {
42+
ERROR: {
4543
on: {
46-
tryAgain: LoginState.LOGIN
44+
tryAgain: 'LOGIN'
4745
}
4846
}
4947
}
5048
}
5149
52-
export default statechart(config, loginChart)
50+
export default statecharts(config, {
51+
login: loginChart
52+
})
5353
`,
5454
},
5555
]
5656
: [
5757
{
5858
fileName: 'overmind/login/index.js',
5959
code: `
60-
import { statechart } from 'overmind/config'
60+
import { statecharts } from 'overmind/config'
6161
import * as actions from './actions'
6262
import { state } from './state'
6363
@@ -95,7 +95,9 @@ const loginChart = {
9595
}
9696
}
9797
98-
export default statechart(config, loginChart)
98+
export default statecharts(config, {
99+
login: loginChart
100+
})
99101
`,
100102
},
101103
]

packages/overmind-website/examples/guide/statecharts/matches.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ export default (ts, view) =>
33
? [
44
{
55
code: `
6-
state.login.matches(LoginState.Login)
6+
state.login.matches({
7+
login: {
8+
LOGIN: true
9+
}
10+
})
711
`,
812
},
913
]
1014
: [
1115
{
1216
code: `
13-
state.login.matches('LOGIN')
17+
state.login.matches({
18+
login: {
19+
LOGIN: true
20+
}
21+
})
1422
`,
1523
},
1624
]

packages/overmind-website/examples/guide/statecharts/matches_multiple.ts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,72 @@ export default (ts, view) =>
33
? [
44
{
55
code: `
6-
state.login.matches(DashboardState.ISSUES, IssuesState.LOADING)
6+
// Nested
7+
const isSearching = state.dashboard.matches({
8+
issues: {
9+
LIST: {
10+
search: {
11+
SEARCHING: true
12+
}
13+
}
14+
}
15+
})
16+
17+
// Parallel
18+
const isDownloadingAndUploading = state.files.matches({
19+
download: {
20+
LOADING: true
21+
},
22+
upload: {
23+
LOADING: true
24+
}
25+
})
26+
27+
// Complex match
28+
const isOnlyDownloading = state.files.matches({
29+
download: {
30+
LOADING: true
31+
},
32+
upload: {
33+
LOADING: false
34+
}
35+
})
736
`,
837
},
938
]
1039
: [
1140
{
1241
code: `
13-
state.login.matches('ISSUES', 'LOADING')
42+
// Nested
43+
const isSearching = state.dashboard.matches({
44+
issues: {
45+
LIST: {
46+
search: {
47+
SEARCHING: true
48+
}
49+
}
50+
}
51+
})
52+
53+
// Parallel
54+
const isDownloadingAndUploading = state.files.matches({
55+
download: {
56+
LOADING: true
57+
},
58+
upload: {
59+
LOADING: true
60+
}
61+
})
62+
63+
// Complex match
64+
const isOnlyDownloading = state.files.matches({
65+
download: {
66+
LOADING: true
67+
},
68+
upload: {
69+
LOADING: false
70+
}
71+
})
1472
`,
1573
},
1674
]

0 commit comments

Comments
 (0)