11import * as CR from 'typings'
2+ import * as G from 'typings/graphql'
23import { Machine } from 'xstate'
4+ import { authenticateMachine } from './authenticate'
35import { selectTutorialMachine } from './selectTutorial'
46import { playTutorialMachine } from './playTutorial'
57
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 > ( {
727 id : 'root' ,
8- initial : 'SelectTutorial ' ,
28+ initial : 'Initializing ' ,
929 context : {
1030 error : null ,
1131 env : { machineId : '' , sessionId : '' , token : '' } ,
1232 tutorial : null ,
1333 } ,
1434 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+
1548 // start/continue a tutorial
1649 // select tutorial
1750 // view tutorial summary
18- SelectTutorial : {
51+ Start : {
1952 invoke : {
2053 src : selectTutorialMachine ,
2154 onDone : 'PlayTutorial' ,
2255 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 ,
2558 error : null ,
2659 } ,
2760 } ,
2861 } ,
62+
2963 // initialize a selected tutorial
3064 // progress through tutorial level/steps
3165 // complete tutorial
@@ -34,8 +68,8 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
3468 src : playTutorialMachine ,
3569 onDone : 'SelectTutorial' ,
3670 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 ,
3973 error : null ,
4074 } ,
4175 } ,
0 commit comments