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

Commitb358130

Browse files
committed
fix send data to client
1 parent98c9cc9 commitb358130

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

‎src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export const editor = new Editor({
1414
setWorkspaceRoot,
1515
})
1616

17+
// TODO: refactor tutorial & editor relationships
18+
// code here is a bit smelly
19+
tutorial.setClientDispatch(editor.dispatch)
20+
1721
// activate run on vscode extension initialization
1822
exportconstactivate=editor.activate
1923

‎src/services/tutorial/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ interface TutorialConfig {
99
testRunner:G.EnumTestRunner
1010
}
1111

12+
interfacePositionProgress{
13+
position:CR.Position
14+
progress:CR.Progress
15+
}
16+
1217
exportinterfaceTutorialModel{
1318
repo:G.TutorialRepo
1419
config:TutorialConfig
@@ -20,9 +25,10 @@ export interface TutorialModel {
2025
level(levelId?:string):G.Level
2126
stage(stageId?:string):G.Stage
2227
step(stepId?:string):G.Step
23-
updateProgress():{position:CR.Position,progress:CR.Progress}
28+
updateProgress():PositionProgress
2429
nextPosition():CR.Position
2530
hasExisting():Promise<boolean>
31+
setClientDispatch(editorDispatch:CR.EditorDispatch):void
2632
}
2733

2834
classTutorialimplementsTutorialModel{
@@ -31,9 +37,13 @@ class Tutorial implements TutorialModel {
3137
publicversion:G.TutorialVersion
3238
publicposition:CR.Position
3339
publicprogress:CR.Progress
40+
privateclientDispatch:(props:PositionProgress)=>void
3441

3542
constructor(){
3643
// initialize types, will be assigned when tutorial is selected
44+
this.clientDispatch=(props:PositionProgress)=>{
45+
thrownewError('Tutorial client dispatch yet initialized')
46+
}
3747
this.repo={}asG.TutorialRepo
3848
this.config={}asTutorialConfig
3949
this.version={}asG.TutorialVersion
@@ -51,6 +61,10 @@ class Tutorial implements TutorialModel {
5161

5262
}
5363

64+
publicsetClientDispatch(editorDispatch:CR.EditorDispatch){
65+
this.clientDispatch=({progress, position}:PositionProgress)=>editorDispatch('SEND_DATA',{progress, position})
66+
}
67+
5468
publicinit=(tutorial:G.Tutorial)=>{
5569
this.repo=tutorial.repo
5670
this.config={
@@ -73,6 +87,11 @@ class Tutorial implements TutorialModel {
7387
complete:false,
7488
}
7589

90+
this.clientDispatch({
91+
position:this.position,
92+
progress:this.progress
93+
})
94+
7695
// set tutorial, position, progress locally
7796
// TODO: base position off of progress
7897
Promise.all([

‎src/state/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ class StateMachine {
4242
.onTransition(state=>{
4343
if(state.changed){
4444
console.log(`STATE:${stateToString(state.value)}`)
45-
dispatch('coderoad.send_state',{state:state.value,data:state.context})
46-
}else{
47-
dispatch('coderoad.send_data',{data:state.context})
45+
dispatch('coderoad.send_state',{state:state.value})
4846
}
4947
})
5048
}
@@ -58,8 +56,8 @@ class StateMachine {
5856
publicrefresh(){
5957
console.log('service refresh')
6058
console.log(this.service.state)
61-
const{value, context}=this.service.state
62-
this.dispatch('coderoad.send_state',{state:value,data:context})
59+
const{value}=this.service.state
60+
this.dispatch('coderoad.send_state',{state:value})
6361
}
6462
publicsend(action:string|CR.Action){
6563
this.service.send(action)

‎web-app/src/App.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ const App = () => {
2828
consthandleEvent=(event:ReceivedEvent):void=>{
2929
constmessage=event.data
3030
// messages from core
31-
const{ progress, position}=message.payload.data
3231

3332
if(message.type==='SET_STATE'){
3433
// SET_STATE - set state machine state
3534
setState(message.payload.state)
36-
37-
setStatus({variables:{ progress, position}})
35+
3836
}elseif(message.type==='SET_DATA'){
3937
// SET_DATA - set state machine context
38+
const{ progress, position}=message.payload.data
4039
setStatus({variables:{ progress, position}})
4140
}
4241
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp