Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit923ea37

Browse files
committed
replace stepNext guards with actions
1 parent95f6f73 commit923ea37

File tree

4 files changed

+44
-58
lines changed

4 files changed

+44
-58
lines changed

‎web-app/src/components/Router/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import debuggerWrapper from '../Debugger/debuggerWrapper'
88
importchannelfrom'../../services/channel'
99
importmessageBusReceiverfrom'../../services/channel/receiver'
1010
importactionsfrom'../../services/state/actions'
11-
importguardsfrom'../../services/state/guards'
1211

1312

1413
interfaceProps{
@@ -24,7 +23,6 @@ interface CloneElementProps {
2423
constRouter=({ children}:Props):React.ReactElement<CloneElementProps>|null=>{
2524
const[state,send]=useMachine(machine,{
2625
actions,
27-
guards,
2826
interpreterOptions:{
2927
logger:console.log.bind('XSTATE:')
3028
}

‎web-app/src/services/state/actions/index.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,50 @@ import {send} from 'xstate'
22
// import {machine} from '../../extension'
33
// import {cache} from '../../services/apollo'
44
// import {editorDispatch} from '../../services/vscode'
5-
//import * as CR from 'typings'
6-
//import * as G from 'typings/graphql'
5+
import*asCRfrom'typings'
6+
import*asGfrom'typings/graphql'
77
// import tutorialConfig from '../../services/apollo/queries/tutorialConfig'
88
importeditorActionsfrom'./editor'
99
importcontextActionsfrom'./context'
1010

1111
exportdefault{
12-
newOrContinue:send((context):'NEW'|'CONTINUE'=>{
12+
newOrContinue:send((context:CR.MachineContext):'NEW'|'CONTINUE'=>{
1313
console.log('new or continue')
1414

1515
// TODO: verify that the user has an existing tutorial to continue
1616
consthasExistingTutorial:boolean=false
1717
returnhasExistingTutorial ?'CONTINUE' :'NEW'
1818
}),
19+
stepNext:send((context:CR.MachineContext):CR.Action=>{
20+
const{tutorial, position, progress}=context
21+
// TODO: protect against errors
22+
conststeps:G.Step[]=tutorial.version
23+
.levels.find((l:G.Level)=>l.id===position.levelId)
24+
.stages.find((s:G.Stage)=>s.id===position.stageId)
25+
.steps
26+
27+
// TODO: verify not -1
28+
conststepIndex=steps.findIndex((s:G.Step)=>s.id===position.stepId)
29+
constfinalStep=stepIndex===steps.length-1
30+
conststepComplete=progress.steps[position.stepId]
31+
// not final step, or final step but not complete
32+
consthasNextStep=!finalStep||!stepComplete
33+
34+
if(hasNextStep){
35+
constnextStep=steps[stepIndex+1]
36+
return{
37+
type:'LOAD_NEXT_STEP',
38+
payload:{
39+
step:nextStep
40+
}
41+
}
42+
}else{
43+
return{
44+
type:'STAGE_COMPLETE'
45+
}
46+
}
47+
48+
}),
1949
...editorActions,
2050
...contextActions,
2151
}

‎web-app/src/services/state/guards/index.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

‎web-app/src/services/state/machine.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,17 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
138138
},
139139
},
140140
StepNext:{
141-
after:{
142-
0:[
143-
{
144-
target:'Normal',
145-
cond:'hasNextStep',
146-
actions:['loadStep'],
147-
},
148-
{
149-
target:'StageComplete',
150-
actions:['updateStageProgress']
151-
},
152-
],
153-
},
141+
onEntry:['stepNext'],
142+
on:{
143+
LOAD_NEXT_STEP:{
144+
target:'Normal',
145+
actions:['loadStep']
146+
},
147+
STAGE_COMPLETE:{
148+
target:"StageComplete",
149+
actions:['updateStageProgress']
150+
}
151+
}
154152
},
155153
StageComplete:{
156154
on:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp