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

Commita87e5c7

Browse files
committed
cleanup machine actions
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parentcc0d642 commita87e5c7

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ declare let acquireVsCodeApi: any
1717

1818
consteditor=acquireVsCodeApi()
1919
consteditorSend=(action:T.Action)=>{
20-
logger(`CLIENTTO EXT: "${action.type}"`)
20+
logger(`TO EXT: "${action.type}"`)
2121
returneditor.postMessage(action)
2222
}
2323

2424
// router finds first state match of <Route path='' />
2525
constuseRouter=():Output=>{
2626
const[state,send]=useMachine<T.MachineContext,any>(createMachine({ editorSend}))
2727

28+
constsendWithLog=(action:T.Action):void=>{
29+
logger(`SEND:${action.type}`,action)
30+
send(action)
31+
}
32+
2833
logger(`STATE:${JSON.stringify(state.value)}`)
2934

3035
// event bus listener
@@ -38,8 +43,7 @@ const useRouter = (): Output => {
3843
if(action.source){
3944
return
4045
}
41-
logger(`CLIENT RECEIVED: "${action.type}"`)
42-
send(action)
46+
sendWithLog(action)
4347
}
4448
window.addEventListener(listener,handler)
4549
return()=>{
@@ -74,7 +78,7 @@ const useRouter = (): Output => {
7478

7579
return{
7680
context:state.context,
77-
send,
81+
send:sendWithLog,
7882
Router,
7983
Route,
8084
}

‎web-app/src/containers/Tutorial/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const TutorialPage = (props: PageProps) => {
2323

2424
constonContinue=():void=>{
2525
props.send({
26-
type:'LEVEL_NEXT',
26+
type:'NEXT_LEVEL',
2727
payload:{
28-
LevelId:position.levelId,
28+
levelId:position.levelId,
2929
},
3030
})
3131
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as TT from 'typings/tutorial'
33
import{assign,send,ActionFunctionMap}from'xstate'
44
import*asselectorsfrom'../../selectors'
55
importonErrorfrom'../../../services/sentry/onError'
6+
importloggerfrom'services/logger'
67

78
constcontextActions:ActionFunctionMap<T.MachineContext,T.MachineEvent>={
89
//@ts-ignore
@@ -33,7 +34,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
3334
},
3435
}),
3536
//@ts-ignore
36-
startNewTutorial:assign({
37+
startTutorial:assign({
3738
position:(context:T.MachineContext,event:T.MachineEvent):any=>{
3839
constposition:T.Position=selectors.initialPosition(context)
3940
returnposition
@@ -119,8 +120,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
119120
//@ts-ignore
120121
updatePosition:assign({
121122
position:(context:T.MachineContext,event:T.MachineEvent):any=>{
122-
const{ position}=event.payload
123-
returnposition
123+
returnevent.payload
124124
},
125125
}),
126126
loadNext:send(
@@ -140,7 +140,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
140140
// NEXT STEP
141141
if(hasNextStep){
142142
constnextPosition={ ...position,stepId:steps[stepIndex+1].id}
143-
return{type:'NEXT_STEP',payload:{position:nextPosition}}
143+
return{type:'NEXT_STEP',payload:nextPosition}
144144
}
145145

146146
// has next level?
@@ -164,7 +164,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
164164
levelId:nextLevel.id,
165165
stepId:nextLevel.steps[0].id,
166166
}
167-
return{type:'NEXT_LEVEL',payload:{position:nextPosition}}
167+
return{type:'NEXT_LEVEL',payload:nextPosition}
168168
}
169169

170170
// COMPLETED
@@ -230,8 +230,9 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
230230
error:():any=>null,
231231
}),
232232
//@ts-ignore
233-
checkEmptySteps:send((context:T.MachineContext)=>{
233+
checkLevelCompleted:send((context:T.MachineContext)=>{
234234
// no step id indicates no steps to complete
235+
logger(context.position)
235236
return{
236237
type:context.position.stepId===null ?'START_COMPLETED_LEVEL' :'START_LEVEL',
237238
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const createMachine = (options: any) => {
9797
on:{
9898
NEW_TUTORIAL:'ValidateSetup',
9999
CONTINUE_TUTORIAL:{
100-
target:'#tutorial-level',
100+
target:'StartTutorial',
101101
actions:['continueConfig'],
102102
},
103103
CONTINUE_FAILED:{
@@ -127,7 +127,7 @@ export const createMachine = (options: any) => {
127127
},
128128
},
129129
StartTutorial:{
130-
onEntry:['startNewTutorial'],
130+
onEntry:['startTutorial'],
131131
after:{
132132
0:'#tutorial',
133133
},
@@ -157,7 +157,7 @@ export const createMachine = (options: any) => {
157157
initial:'Load',
158158
states:{
159159
Load:{
160-
onEntry:['loadLevel','loadStep','checkEmptySteps'],
160+
onEntry:['loadLevel','loadStep','checkLevelCompleted'],
161161
on:{
162162
START_LEVEL:'Normal',
163163
START_COMPLETED_LEVEL:'LevelComplete',
@@ -214,9 +214,9 @@ export const createMachine = (options: any) => {
214214
onEntry:['updateLevelProgress'],
215215
onExit:['syncLevelProgress'],
216216
on:{
217-
LEVEL_NEXT:{
217+
NEXT_LEVEL:{
218218
target:'#tutorial-load-next',
219-
actions:['testClear'],
219+
actions:['testClear','updatePosition'],
220220
},
221221
},
222222
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp