1
1
import * as CR from 'typings'
2
+ import * as G from 'typings/graphql'
2
3
import { Machine } from 'xstate'
4
+ import { authenticateMachine } from './authenticate'
3
5
import { selectTutorialMachine } from './selectTutorial'
4
6
import { playTutorialMachine } from './playTutorial'
5
7
6
- export const machine = Machine < CR . MachineContext , CR . MachineStateSchema , CR . MachineEvent > ( {
8
+ export type MachineEvent = {
9
+ type : 'NONE'
10
+ }
11
+
12
+ export type MachineContext = {
13
+ env : CR . Environment
14
+ error : CR . ErrorMessage | null
15
+ tutorial : G . Tutorial | null
16
+ }
17
+
18
+ export type MachineStateSchema = {
19
+ states : {
20
+ Initializing : { }
21
+ Start : { }
22
+ PlayTutorial : { }
23
+ }
24
+ }
25
+
26
+ export const machine = Machine < MachineContext , MachineStateSchema , MachineEvent > ( {
7
27
id : 'root' ,
8
- initial : 'SelectTutorial ' ,
28
+ initial : 'Initializing ' ,
9
29
context : {
10
30
error : null ,
11
31
env : { machineId : '' , sessionId : '' , token : '' } ,
12
32
tutorial : null ,
13
33
} ,
14
34
states : {
35
+ // load environment
36
+ // authenticate with environment
37
+ Initializing : {
38
+ invoke : {
39
+ src : authenticateMachine ,
40
+ onDone : 'Start' ,
41
+ data : {
42
+ env : ( context : MachineContext ) => context . env ,
43
+ error : null ,
44
+ } ,
45
+ } ,
46
+ } ,
47
+
15
48
// start/continue a tutorial
16
49
// select tutorial
17
50
// view tutorial summary
18
- SelectTutorial : {
51
+ Start : {
19
52
invoke : {
20
53
src : selectTutorialMachine ,
21
54
onDone : 'PlayTutorial' ,
22
55
data : {
23
- env : ( context : CR . MachineContext ) => context . env ,
24
- tutorial : ( context : CR . MachineContext ) => context . tutorial ,
56
+ env : ( context : MachineContext ) => context . env ,
57
+ tutorial : ( context : MachineContext ) => context . tutorial ,
25
58
error : null ,
26
59
} ,
27
60
} ,
28
61
} ,
62
+
29
63
// initialize a selected tutorial
30
64
// progress through tutorial level/steps
31
65
// complete tutorial
@@ -34,8 +68,8 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
34
68
src : playTutorialMachine ,
35
69
onDone : 'SelectTutorial' ,
36
70
data : {
37
- context : ( context : CR . MachineContext ) => context . env ,
38
- tutorial : ( context : CR . MachineContext ) => context . tutorial ,
71
+ context : ( context : MachineContext ) => context . env ,
72
+ tutorial : ( context : MachineContext ) => context . tutorial ,
39
73
error : null ,
40
74
} ,
41
75
} ,
0 commit comments