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

Commit6217ea6

Browse files
committed
align channel with context
1 parent1a9ccf9 commit6217ea6

File tree

4 files changed

+125
-186
lines changed

4 files changed

+125
-186
lines changed

‎src/Channel.ts

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

‎src/channel/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Context {
1717
this.position=newPosition()
1818
this.progress=newProgress()
1919
}
20-
setTutorial(tutorial:G.Tutorial,workspaceState:vscode.Memento){
20+
setTutorial(workspaceState:vscode.Memento,tutorial:G.Tutorial){
2121
this.tutorial.set(tutorial)
2222
this.progress.setTutorial(workspaceState,tutorial)
2323
}

‎src/channel/index.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import*asCRfrom'typings'
2+
import*asGfrom'typings/graphql'
3+
import*asvscodefrom'vscode'
4+
5+
importContextfrom'./context'
6+
importtutorialConfigfrom'../actions/tutorialConfig'
7+
importsetupActionsfrom'../actions/setupActions'
8+
importsolutionActionsfrom'../actions/solutionActions'
9+
importsaveCommitfrom'../actions/saveCommit'
10+
11+
12+
interfaceChannel{
13+
receive(action:CR.Action):Promise<void>
14+
send(action:CR.Action):Promise<void>
15+
}
16+
17+
interfaceChannelProps{
18+
postMessage:(action:CR.Action)=>Thenable<boolean>
19+
workspaceState:vscode.Memento
20+
}
21+
22+
23+
classChannelimplementsChannel{
24+
privatepostMessage:(action:CR.Action)=>Thenable<boolean>
25+
privateworkspaceState:vscode.Memento
26+
privatecontext:Context
27+
constructor({postMessage, workspaceState}:ChannelProps){
28+
// workspaceState used for local storage
29+
this.workspaceState=workspaceState
30+
this.postMessage=postMessage
31+
this.context=newContext(workspaceState)
32+
}
33+
34+
// receive from webview
35+
publicreceive=async(action:CR.Action)=>{
36+
constactionType:string=typeofaction==='string' ?action :action.type
37+
console.log('RECEIVED:',actionType)
38+
switch(actionType){
39+
// continue from tutorial from local storage
40+
case'EDITOR_TUTORIAL_LOAD':
41+
consttutorial:G.Tutorial|null=this.context.tutorial.get()
42+
43+
// new tutorial
44+
if(!tutorial||!tutorial.id||!tutorial.version){
45+
this.send({type:'NEW_TUTORIAL'})
46+
return
47+
}
48+
49+
// set tutorial
50+
constprogress:CR.Progress=awaitthis.context.progress.setTutorial(this.workspaceState,tutorial)
51+
52+
console.log('looking at stored')
53+
console.log(JSON.stringify(tutorial))
54+
console.log(JSON.stringify(progress))
55+
56+
if(progress.complete){
57+
// tutorial is already complete
58+
this.send({type:'NEW_TUTORIAL'})
59+
return
60+
}
61+
62+
// communicate to client the tutorial & stepProgress state
63+
this.send({type:'CONTINUE_TUTORIAL',payload:{tutorial, progress, position}})
64+
65+
return
66+
// clear tutorial local storage
67+
case'TUTORIAL_CLEAR':
68+
// clear current progress/position/tutorial
69+
this.context=newContext(this.workspaceState)
70+
return
71+
// configure test runner, language, git
72+
case'EDITOR_TUTORIAL_CONFIG':
73+
consttutorialData=action.payload.tutorial
74+
console.log('tutorialConfig',JSON.stringify(tutorialData))
75+
this.context.setTutorial(this.workspaceState,tutorialData)
76+
tutorialConfig(tutorialData)
77+
return
78+
// run unit tests on step
79+
case'TEST_RUN':
80+
vscode.commands.executeCommand('coderoad.run_test',action.payload)
81+
return
82+
// load step actions (git commits, commands, open files)
83+
case'SETUP_ACTIONS':
84+
vscode.commands.executeCommand('coderoad.set_current_step',action.payload)
85+
setupActions(action.payload)
86+
return
87+
// load solution step actions (git commits, commands, open files)
88+
case'SOLUTION_ACTIONS':
89+
solutionActions(action.payload)
90+
return
91+
92+
default:
93+
console.log(`No match for action type:${actionType}`)
94+
return
95+
}
96+
}
97+
// send to webview
98+
publicsend=async(action:CR.Action)=>{
99+
100+
switch(action.type){
101+
case'TEST_PASS':
102+
// update local storage stepProgress
103+
this.context.progress.setStepComplete(action.payload.stepId)
104+
saveCommit()
105+
}
106+
107+
constsuccess=awaitthis.postMessage(action)
108+
if(!success){
109+
thrownewError(`Message post failure:${JSON.stringify(action)}`)
110+
}
111+
}
112+
113+
}
114+
115+
exportdefaultChannel
116+

‎src/channel/state/Progress.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ class Progress {
1818
constructor(){
1919
this.value=defaultValue
2020
}
21-
publicsetTutorial=(workspaceState:vscode.Memento,tutorial:G.Tutorial)=>{
21+
publicsetTutorial=async(workspaceState:vscode.Memento,tutorial:G.Tutorial):Promise<CR.Progress>=>{
2222
this.storage=newStorage<CR.Progress>({
2323
key:`coderoad:progress:${tutorial.id}:${tutorial.version}`,
2424
storage:workspaceState,
2525
defaultValue,
2626
})// set value from storage
27-
this.storage.get().then((value:CR.Progress)=>{
28-
this.value=value
29-
})
27+
this.value=awaitthis.storage.get()
28+
returnthis.value
3029
}
3130
publicget=()=>{
3231
returnthis.value
@@ -37,6 +36,11 @@ class Progress {
3736
this.storage.set(value)
3837
}
3938
}
39+
publicsetStepComplete=(stepId:string)=>{
40+
constnext=this.value
41+
next.steps[stepId]=true
42+
this.set(next)
43+
}
4044
}
4145

4246
exportdefaultProgress

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp