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

Commit3cdce4d

Browse files
committed
setup state/data
1 parent08b28af commit3cdce4d

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

‎src/editor/commands/index.ts

Lines changed: 6 additions & 6 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+
SEND_DATA:'coderoad.send_data',
1213
RECEIVE_ACTION:'coderoad.receive_action',
1314
OPEN_FILE:'coderoad.open_file',
1415
RUN_TEST:'coderoad.test_run',
@@ -70,15 +71,14 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
7071
}
7172
},
7273
// send messages to webview
73-
[COMMANDS.SEND_STATE]:(payload:any)=>{
74-
console.log(`SEND${JSON.stringify(payload)}`)
75-
// console.log(webview.currentPanel)
76-
// if (!webview || !webview.currentPanel) {
77-
// throw new Error('No valid panel available')
78-
// }
74+
[COMMANDS.SEND_STATE]:(payload:{data:any,state:any})=>{
7975
webview.postMessage({type:'SET_STATE', payload})
8076
},
77+
[COMMANDS.SEND_DATA]:(payload:{data:any})=>{
78+
webview.postMessage({type:'SET_DATA', payload})
79+
},
8180
[COMMANDS.RECEIVE_ACTION]:(action:string|CR.Action)=>{
81+
console.log('onReceiveAction',action)
8282
machine.onReceive(action)
8383
}
8484
})

‎src/state/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ class StateMachine {
1818
this.service=interpret(machine,this.machineOptions)
1919
// logging
2020
.onTransition(state=>{
21-
console.log('onTransition',state.changed)
21+
console.log('onTransition',state)
2222
if(state.changed){
2323
console.log('next state')
2424
console.log(state.value)
25-
vscode.commands.executeCommand('coderoad.send_state',state.value)
25+
vscode.commands.executeCommand('coderoad.send_state',{state:state.value,data:state.context})
26+
}else{
27+
vscode.commands.executeCommand('coderoad.send_data',{data:state.context})
2628
}
2729
})
2830
}

‎web-app/src/Routes.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import*asReactfrom'react'
22
import*asCRfrom'typings'
3+
import{send}from'./utils/vscode'
4+
35
importNewPagefrom'./components/New'
46
importContinuePagefrom'./components/Continue'
57
importCondfrom'./components/Cond'
@@ -8,23 +10,21 @@ interface ReceivedEvent {
810
data:CR.Action
911
}
1012

11-
declarevaracquireVsCodeApi:any
12-
13-
constvscode=acquireVsCodeApi()
14-
15-
functionsend(event:string|CR.Action){
16-
returnvscode.postMessage(event)
17-
}
18-
19-
2013
constRoutes=()=>{
2114
const[state,setState]=React.useState({SelectTutorial:'Initial'})
15+
const[data,setData]=React.useState({})
16+
17+
2218
consthandleEvent=(event:ReceivedEvent):void=>{
2319
constmessage=event.data
24-
console.log(`RECEIVED:${JSON.stringify(message)}`)
20+
console.log('RECEIVED')
21+
console.log(message)
2522
// messages from core
2623
if(message.type==='SET_STATE'){
27-
setState(message.payload)
24+
setState(message.payload.state)
25+
setData(message.payload.data)
26+
}elseif(message.type==='SET_DATA'){
27+
setData(message.payload.data)
2828
}
2929
}
3030

@@ -37,8 +37,11 @@ const Routes = () => {
3737
}
3838
})
3939

40+
// TODO: refactor cond to user <Router><Route> and accept first route as if/else if
4041
return(
4142
<div>
43+
<h5>state:{JSON.stringify(state)}</h5>
44+
<p>data:{JSON.stringify(data)}</p>
4245
<Condstate={state}path="SelectTutorial.NewTutorial">
4346
<NewPageonNew={()=>send('TUTORIAL_START')}/>
4447
</Cond>

‎web-app/src/utils/vscode.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import{Action}from'typings'
2+
3+
declarevaracquireVsCodeApi:any
4+
5+
constvscode=acquireVsCodeApi()
6+
7+
exportfunctionsend(event:string|Action){
8+
returnvscode.postMessage(event)
9+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp