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

Commited19795

Browse files
committed
cleanup machine
1 parent55661c9 commited19795

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import*asReactfrom'react'
22
import*asCRfrom'typings'
3-
import{useMachine}from'@xstate/react'
3+
import{useMachine}from'../../services/xstate-react'
44
importmachinefrom'../../services/state/machine'
55

66
importRoutefrom'./Route'
77
importdebuggerWrapperfrom'../Debugger/debuggerWrapper'
88
importchannelfrom'../../services/channel'
99
importmessageBusReceiverfrom'../../services/channel/receiver'
10+
importactionsfrom'../../services/state/actions'
11+
importguardsfrom'../../services/state/guards'
12+
1013

1114
interfaceProps{
1215
children:any
@@ -20,11 +23,13 @@ interface CloneElementProps {
2023
// router finds first state match of <Route path='' />
2124
constRouter=({ children}:Props):React.ReactElement<CloneElementProps>|null=>{
2225
const[state,send]=useMachine(machine,{
23-
logger:console.log.bind('XSTATE:')
26+
actions,
27+
guards,
28+
interpreterOptions:{
29+
logger:console.log.bind('XSTATE:')
30+
}
2431
})
2532

26-
console.log('state',state)
27-
2833
channel.setMachineSend(send)
2934

3035
// event bus listener

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,14 @@ export default {
3636
stepId,
3737
}
3838
})
39-
}
39+
},
40+
loadLevel():void{
41+
// load step actions
42+
},
43+
loadStage():void{
44+
// load step actions
45+
},
46+
loadStep():void{
47+
// load step actions
48+
},
4049
}

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

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import{Machine}from'xstate'
22
import*asCRfrom'typings'
33

4-
importactionsfrom'./actions'
5-
importguardsfrom'./guards'
6-
74
exportconstmachine=Machine<CR.MachineContext,CR.MachineStateSchema,CR.MachineEvent>(
85
{
96
id:'root',
@@ -69,26 +66,22 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
6966
},
7067
LoadNext:{
7168
id:'tutorial-load-next',
72-
after:{
73-
0:[{
69+
onEntry:['loadNext'],
70+
on:{
71+
NEXT_STEP:{
7472
target:'Stage',
75-
cond:'hasNextStep',
73+
actions:['updatePosition']
7674
},
77-
{
75+
NEXT_STAGE:{
7876
target:'Stage',
79-
cond:'hasNextStage',
80-
actions:['updateStagePosition']
77+
actions:['updatePosition']
8178
},
82-
{
79+
NEXT_LEVEL:{
8380
target:'Level',
84-
cond:'hasNextLevel',
85-
actions:['updateLevelPosition']
86-
},
87-
{
88-
target:'#completed-tutorial',
81+
actions:['updatePosition']
8982
},
90-
],
91-
},
83+
COMPLETED:'#completed-tutorial'
84+
}
9285
},
9386

9487
Summary:{
@@ -107,7 +100,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
107100
},
108101
},
109102
Stage:{
110-
onEntry:['loadStage','stepLoadCommits'],
103+
onEntry:['loadStage'],
111104
initial:'Normal',
112105
states:{
113106
Normal:{
@@ -126,6 +119,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
126119
on:{
127120
TEST_PASS:{
128121
target:'TestPass',
122+
// TODO: combine updateStepProgress & updateStepPosition
129123
actions:['updateStepProgress']
130124
},
131125
TEST_FAIL:'TestFail',
@@ -149,7 +143,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
149143
{
150144
target:'Normal',
151145
cond:'hasNextStep',
152-
actions:['stepLoadCommits'],
146+
actions:['loadStep'],
153147
},
154148
{
155149
target:'StageComplete',
@@ -177,12 +171,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
177171
},
178172
},
179173
},
180-
},
181-
{
182-
actions,
183-
guards,
184-
activities:{},
185-
},
174+
}
186175
)
187176

188177
exportdefaultmachine

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp