11import * as CR from 'typings'
22import * as G from 'typings/graphql'
3+ import * as Event from 'typings/events'
34import { assign , send , ActionFunctionMap } from 'xstate'
4- import { MachineContext , MachineEvent } from './index'
5+ import { MachineContext } from './index'
56import channel from '../../channel'
67import onError from '../../sentry/onError'
78import * as selectors from '../../selectors'
89
9- const actions : ActionFunctionMap < MachineContext , MachineEvent > = {
10+ const actions : ActionFunctionMap < MachineContext , Event . PlayTutorialEvents > = {
1011 userTutorialComplete ( context : MachineContext ) {
1112 console . log ( 'should update user tutorial as complete' )
1213 } ,
@@ -29,27 +30,21 @@ const actions: ActionFunctionMap<MachineContext, MachineEvent> = {
2930 } ) ,
3031 // @ts -ignore
3132 commandSuccess : assign ( {
32- processes : (
33- { processes } : MachineContext ,
34- event : { type : 'COMMAND_SUCCESS' ; payload : { process : CR . ProcessEvent } } ,
35- ) : CR . ProcessEvent [ ] => {
33+ processes : ( { processes } : MachineContext , event : Event . CommandSuccessEvent ) : CR . ProcessEvent [ ] => {
3634 const { process } = event . payload
3735 return processes . filter ( p => p . title !== process . title )
3836 } ,
3937 } ) ,
4038 // @ts -ignore
4139 commandFail : assign ( {
42- processes : (
43- { processes } : MachineContext ,
44- event : { type : 'COMMAND_FAIL' ; payload : { process : CR . ProcessEvent } } ,
45- ) : CR . ProcessEvent [ ] => {
40+ processes : ( { processes } : MachineContext , event : Event . CommandFailEvent ) : CR . ProcessEvent [ ] => {
4641 const { process } = event . payload
4742 return processes . filter ( p => p . title !== process . title )
4843 } ,
4944 } ) ,
5045 // @ts -ignore
5146 updateStepPosition : assign ( {
52- position : ( context : MachineContext , event : MachineEvent ) : CR . Position => {
47+ position : ( context : MachineContext , event : Event . PlayTutorialEvents ) : CR . Position => {
5348 // TODO calculate from progress
5449
5550 const { position } = context
@@ -97,7 +92,7 @@ const actions: ActionFunctionMap<MachineContext, MachineEvent> = {
9792 } ) ,
9893 // @ts -ignore
9994 updateLevelProgress : assign ( {
100- progress : ( context : MachineContext , event : MachineEvent ) : CR . Progress => {
95+ progress : ( context : MachineContext , event : Event . PlayTutorialEvents ) : CR . Progress => {
10196 // update progress by tracking completed
10297 const { progress, position } = context
10398
@@ -110,7 +105,7 @@ const actions: ActionFunctionMap<MachineContext, MachineEvent> = {
110105 } ) ,
111106 // @ts -ignore
112107 updateStepProgress : assign ( {
113- progress : ( context : MachineContext , event : { type : 'TEST_PASS' ; payload : { stepId : string } } ) : CR . Progress => {
108+ progress : ( context : MachineContext , event : Event . TestPassEvent ) : CR . Progress => {
114109 // update progress by tracking completed
115110 const currentProgress : CR . Progress = context . progress
116111
@@ -123,12 +118,7 @@ const actions: ActionFunctionMap<MachineContext, MachineEvent> = {
123118 } ) ,
124119 // @ts -ignore
125120 updatePosition : assign ( {
126- position : (
127- context : MachineContext ,
128- event :
129- | { type : 'NEXT_STEP' ; payload : { position : CR . Position } }
130- | { type : 'NEXT_LEVEL' ; payload : { position : CR . Position } } ,
131- ) : CR . Progress => {
121+ position : ( context : MachineContext , event : Event . NextStepEvent | Event . NextLevelEvent ) : CR . Position => {
132122 const { position } = event . payload
133123 return position
134124 } ,
@@ -210,7 +200,7 @@ const actions: ActionFunctionMap<MachineContext, MachineEvent> = {
210200 ) ,
211201 // @ts -ignore
212202 setError : assign ( {
213- error : ( context : MachineContext , event : { type : 'ERROR' ; payload : { error : string } } ) : string | null => {
203+ error : ( context : MachineContext , event : Event . ErrorEvent ) : string | null => {
214204 return event . payload . error
215205 } ,
216206 } ) ,
0 commit comments