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

Commit08b28af

Browse files
committed
run received actions through state machine
1 parent864a26e commit08b28af

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

‎src/editor/ReactWebView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ class ReactWebView {
1212
privatedisposables:vscode.Disposable[]=[]
1313
privateonReceive:any// TODO: properly type
1414

15-
publicconstructor(extensionPath:string,onReceive:any){
15+
publicconstructor(extensionPath:string){
1616
this.extensionPath=extensionPath
17-
this.onReceive=onReceive
1817

1918
// Create and show a new webview panel
2019
this.panel=this.createWebviewPanel(vscode.ViewColumn.One)
@@ -27,7 +26,8 @@ class ReactWebView {
2726
this.panel.onDidDispose(()=>this.dispose(),null,this.disposables)
2827

2928
// Handle messages from the webview
30-
this.panel.webview.onDidReceiveMessage(this.onReceive,null,this.disposables)
29+
constonReceive=(action:string|CR.Action)=>vscode.commands.executeCommand('coderoad.receive_action',action)
30+
this.panel.webview.onDidReceiveMessage(onReceive,null,this.disposables)
3131
console.log('webview loaded')
3232
}
3333

‎src/editor/commands/index.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const COMMANDS = {
99
NEW_OR_CONTINUE:'coderoad.new_or_continue',
1010
OPEN_WEBVIEW:'coderoad.open_webview',
1111
SEND_STATE:'coderoad.send_state',
12+
RECEIVE_ACTION:'coderoad.receive_action',
1213
OPEN_FILE:'coderoad.open_file',
1314
RUN_TEST:'coderoad.test_run',
1415
}
@@ -22,13 +23,6 @@ interface CreateCommandProps {
2223

2324
// React panel webview
2425
letwebview:any;
25-
letinitialTutorial:CR.Tutorial|undefined
26-
letinitialProgress:CR.Progress={
27-
levels:{},
28-
stages:{},
29-
steps:{},
30-
complete:false,
31-
}
3226

3327
exportconstcreateCommands=({ context, machine, storage, git}:CreateCommandProps)=>({
3428
// initialize
@@ -37,7 +31,7 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
3731
setStorage(context.workspaceState)
3832

3933
// activate machine
40-
webview=newReactWebView(context.extensionPath,machine.onReceive)
34+
webview=newReactWebView(context.extensionPath)
4135
console.log('webview',webview.panel.webview.postMessage)
4236
machine.activate()
4337
},
@@ -50,8 +44,6 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
5044
git.gitVersion(),
5145
git.gitCheckRemoteExists(),
5246
])
53-
initialTutorial=tutorial
54-
initialProgress=progress
5547
constcanContinue=!!(tutorial&&progress&&hasGit&&hasGitRemote)
5648
console.log('canContinue',canContinue)
5749
// if a tutorial exists, 'CONTINUE'
@@ -85,6 +77,8 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
8577
// throw new Error('No valid panel available')
8678
// }
8779
webview.postMessage({type:'SET_STATE', payload})
88-
80+
},
81+
[COMMANDS.RECEIVE_ACTION]:(action:string|CR.Action)=>{
82+
machine.onReceive(action)
8983
}
9084
})

‎src/state/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class StateMachine {
3838
console.log(action)
3939
this.service.send(action)
4040
}
41-
onReceive(action:CR.Action){
42-
console.log('RECEIVED ACTION')
41+
onReceive(action:string|CR.Action){
4342
console.log(action)
43+
this.service.send(action)
4444
}
4545
}
4646

‎typings/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,5 @@ export interface StateMachine {
168168
activate():void
169169
deactivate():void
170170
send(action:string|Action):void
171-
onReceive(action:Action):void
171+
onReceive(action:string|Action):void
172172
}

‎web-app/src/Routes.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ interface ReceivedEvent {
88
data:CR.Action
99
}
1010

11+
declarevaracquireVsCodeApi:any
12+
13+
constvscode=acquireVsCodeApi()
14+
15+
functionsend(event:string|CR.Action){
16+
returnvscode.postMessage(event)
17+
}
18+
19+
1120
constRoutes=()=>{
1221
const[state,setState]=React.useState({SelectTutorial:'Initial'})
1322
consthandleEvent=(event:ReceivedEvent):void=>{
@@ -31,7 +40,7 @@ const Routes = () => {
3140
return(
3241
<div>
3342
<Condstate={state}path="SelectTutorial.NewTutorial">
34-
<NewPageonNew={()=>console.log('new!')}/>
43+
<NewPageonNew={()=>send('TUTORIAL_START')}/>
3544
</Cond>
3645
<Condstate={state}path="SelectTutorial.ContinueTutorial">
3746
<ContinuePageonContinue={()=>console.log('continue!')}tutorials={[]}/>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp