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

Commit6113648

Browse files
committed
setup command actions
1 parentaa978af commit6113648

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

‎web-app/src/services/channel/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ interface ReceivedEvent {
77
}
88

99
classChannel{
10+
editorSend:(action:Action)=>void
11+
machineSend:(action:Action|string)=>void
1012
constructor(){
1113
// setup mock if browser only
1214
//@ts-ignore
@@ -19,12 +21,9 @@ class Channel {
1921
consteditor=acquireVsCodeApi()
2022

2123
this.editorSend=editor.postMessage
22-
}
23-
publicmachineSend=(action:Action|string)=>{
24-
/* */
25-
}
26-
publiceditorSend=(action:Action)=>{
27-
/* */
24+
this.machineSend=()=>{
25+
/* machineSend is set asynchronously in the router. see "setMachineSend" */
26+
}
2827
}
2928

3029
publicsetMachineSend=(send:any)=>{
@@ -53,6 +52,10 @@ class Channel {
5352
case'TEST_FAIL':
5453
case'TEST_RUNNING':
5554
case'TEST_ERROR':
55+
case'COMMAND_START':
56+
case'COMMAND_SUCCESS':
57+
case'COMMAND_FAIL':
58+
case'COMMAND_ERROR':
5659
this.machineSend(action)
5760
return
5861
default:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import{assign}from'xstate'
2+
import*asTfrom'typings'
3+
4+
exportdefault{
5+
//@ts-ignore
6+
commandStart:assign({
7+
processes:({ processes}:T.MachineContext,event:T.MachineEvent):T.ProcessEvent[]=>{
8+
const{ process}=event.payload
9+
constisRunning=processes.find(p=>p.title===process.title)
10+
if(!isRunning){
11+
processes=processes.concat(process)
12+
}
13+
returnprocesses
14+
},
15+
}),
16+
//@ts-ignore
17+
commandSuccess:assign({
18+
processes:({ processes}:T.MachineContext,event:T.MachineEvent):T.ProcessEvent[]=>{
19+
const{ process}=event.payload
20+
returnprocesses.filter(p=>p.title===process.title)
21+
},
22+
}),
23+
//@ts-ignore
24+
commandFail:assign({
25+
processes:({ processes}:T.MachineContext,event:T.MachineEvent):T.ProcessEvent[]=>{
26+
const{ process}=event.payload
27+
returnprocesses.filter(p=>p.title===process.title)
28+
},
29+
}),
30+
//@ts-ignore
31+
commandError:assign({
32+
processes:({ processes}:T.MachineContext,event:T.MachineEvent):T.ProcessEvent[]=>{
33+
const{ process}=event.payload
34+
returnprocesses.filter(p=>p.title===process.title)
35+
},
36+
}),
37+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
importeditorActionsfrom'./editor'
22
importcontextActionsfrom'./context'
33
importapiActionsfrom'./api'
4+
importcommandActionsfrom'./command'
45

56
exportdefault{
67
...editorActions,
78
...contextActions,
89
...apiActions,
10+
...commandActions,
911
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,24 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
7777
Tutorial:{
7878
id:'tutorial',
7979
initial:'Initialize',
80+
on:{
81+
COMMAND_START:{
82+
actions:['commandStart'],
83+
},
84+
COMMAND_SUCCESS:{
85+
actions:['commandSuccess'],
86+
},
87+
COMMAND_FAIL:{
88+
actions:['commandFail'],
89+
},
90+
COMMAND_ERROR:{
91+
actions:['commandError'],
92+
},
93+
},
8094
states:{
8195
// TODO: move Initialize into New Tutorial setup
8296
Initialize:{
83-
onEntry:['initializeTutorial'],
97+
onEntry:['initializeTutsorial'],
8498
on:{
8599
TUTORIAL_CONFIGURED:'Summary',
86100
// TUTORIAL_CONFIG_ERROR: 'Start' // TODO: should handle error

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp