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

Commiteda3451

Browse files
committed
create api actions
1 parent923ea37 commiteda3451

File tree

8 files changed

+48
-105
lines changed

8 files changed

+48
-105
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class Channel {
4343
console.log('test passed')
4444
return
4545
default:
46-
console.warn(`Unknown received action${action.type}`,action)
46+
if(action.type){
47+
console.warn(`Unknown received action${action.type}`,action)
48+
}
4749
}
4850
}
4951
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ window.acquireVsCodeApi = () => ({
2626
payload:action.payload,
2727
}
2828
channel.receive(createReceiveEvent(receiveAction))
29-
})
29+
},1000)
3030
default:
3131
console.warn(`${action.type} not found in post message mock`)
3232
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportdefault{
2+
3+
}

‎web-app/src/services/state/actions/context.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,35 @@ export default {
217217
// COMPLETED
218218
return{type:'COMPLETED'}
219219
}),
220+
stepNext:send((context:CR.MachineContext):CR.Action=>{
221+
const{tutorial, position, progress}=context
222+
// TODO: protect against errors
223+
conststeps:G.Step[]=tutorial.version
224+
.levels.find((l:G.Level)=>l.id===position.levelId)
225+
.stages.find((s:G.Stage)=>s.id===position.stageId)
226+
.steps
227+
228+
// TODO: verify not -1
229+
conststepIndex=steps.findIndex((s:G.Step)=>s.id===position.stepId)
230+
constfinalStep=stepIndex===steps.length-1
231+
conststepComplete=progress.steps[position.stepId]
232+
// not final step, or final step but not complete
233+
consthasNextStep=!finalStep||!stepComplete
234+
235+
if(hasNextStep){
236+
constnextStep=steps[stepIndex+1]
237+
return{
238+
type:'LOAD_NEXT_STEP',
239+
payload:{
240+
step:nextStep
241+
}
242+
}
243+
}else{
244+
return{
245+
type:'STAGE_COMPLETE'
246+
}
247+
}
248+
}),
220249
//@ts-ignore
221250
reset:assign({
222251
tutorial(){

‎web-app/src/services/state/actions/editor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
import{send}from'xstate'
12
import*asCRfrom'typings'
23
importchannelfrom'../../channel'
34

45
exportdefault{
6+
newOrContinue:send((context:CR.MachineContext):'NEW'|'CONTINUE'=>{
7+
console.log('new or continue')
8+
// TODO: verify that the user has an existing tutorial to continue
9+
consthasExistingTutorial:boolean=false
10+
returnhasExistingTutorial ?'CONTINUE' :'NEW'
11+
}),
512
tutorialStart(){
613
console.log('EDITOR: TUTORIAL_START')
714
channel.editorSend({
Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,9 @@
1-
import{send}from'xstate'
2-
// import {machine} from '../../extension'
3-
// import {cache} from '../../services/apollo'
4-
// import {editorDispatch} from '../../services/vscode'
5-
import*asCRfrom'typings'
6-
import*asGfrom'typings/graphql'
7-
// import tutorialConfig from '../../services/apollo/queries/tutorialConfig'
81
importeditorActionsfrom'./editor'
92
importcontextActionsfrom'./context'
3+
importapiActionsfrom'./api'
104

115
exportdefault{
12-
newOrContinue:send((context:CR.MachineContext):'NEW'|'CONTINUE'=>{
13-
console.log('new or continue')
14-
15-
// TODO: verify that the user has an existing tutorial to continue
16-
consthasExistingTutorial:boolean=false
17-
returnhasExistingTutorial ?'CONTINUE' :'NEW'
18-
}),
19-
stepNext:send((context:CR.MachineContext):CR.Action=>{
20-
const{tutorial, position, progress}=context
21-
// TODO: protect against errors
22-
conststeps:G.Step[]=tutorial.version
23-
.levels.find((l:G.Level)=>l.id===position.levelId)
24-
.stages.find((s:G.Stage)=>s.id===position.stageId)
25-
.steps
26-
27-
// TODO: verify not -1
28-
conststepIndex=steps.findIndex((s:G.Step)=>s.id===position.stepId)
29-
constfinalStep=stepIndex===steps.length-1
30-
conststepComplete=progress.steps[position.stepId]
31-
// not final step, or final step but not complete
32-
consthasNextStep=!finalStep||!stepComplete
33-
34-
if(hasNextStep){
35-
constnextStep=steps[stepIndex+1]
36-
return{
37-
type:'LOAD_NEXT_STEP',
38-
payload:{
39-
step:nextStep
40-
}
41-
}
42-
}else{
43-
return{
44-
type:'STAGE_COMPLETE'
45-
}
46-
}
47-
48-
}),
496
...editorActions,
507
...contextActions,
8+
...apiActions,
519
}
52-
53-
// export default {
54-
// async newOrContinue() {
55-
// // verify that the user has an existing tutorial to continue
56-
// // const hasExistingTutorial: boolean = await tutorialModel.hasExisting()
57-
// // machine.send(hasExistingTutorial ? 'CONTINUE' : 'NEW')
58-
// },
59-
// testRunnerSetup() {
60-
// const result = cache.readQuery({query: tutorialConfig})
61-
// console.log('result', result)
62-
// // const codingLanguage: G.EnumCodingLanguage = result.data.codingLanguage
63-
// // editorDispatch('coderoad.test_runner_setup', codingLanguage)
64-
// },
65-
// initializeNewTutorial: assign({
66-
// position: (context: any): CR.Position => {
67-
// const { tutorial } = context
68-
// const levelId = data.summary.levelList[0]
69-
// const stageId = data.levels[levelId].stageList[0]
70-
// const stepId = data.stages[stageId].stepList[0]
71-
// return {
72-
// levelId,
73-
// stageId,
74-
// stepId,
75-
// }
76-
// },
77-
// })
78-
// tutorialContinue() {
79-
// console.log('tutorial continue')
80-
// },
81-
// testStart() {
82-
// editorDispatch('coderoad.run_test')
83-
// },
84-
// testPass(): void {
85-
// editorDispatch('coderoad.test_pass')
86-
// // git.gitSaveCommit(tutorialModel.position)
87-
// },
88-
// testFail() {
89-
// editorDispatch('coderoad.test_fail')
90-
// },
91-
// //@ts-ignore
92-
// progressUpdate() {
93-
// // tutorialModel.updateProgress()
94-
// // tutorialModel.nextPosition()
95-
// },
96-
97-
// stageLoadNext() {
98-
// console.log('stageLoadNext')
99-
// // tutorialModel.nextPosition()
100-
// },
101-
// loadStage(): void {
102-
// // tutorialModel.triggerCurrent('STAGE')
103-
// },
104-
// stepLoadCommits(): void {
105-
// // tutorialModel.triggerCurrent('STEP')
106-
// },
107-
// }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
5959
initial:'Initialize',
6060
states:{
6161
Initialize:{
62-
onEntry:['initializeNewTutorial'],
6362
after:{
6463
0:'Summary',
6564
},
@@ -159,6 +158,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
159158
},
160159
Completed:{
161160
id:'completed-tutorial',
161+
onEntry:['syncCompleted'],
162162
on:{
163163
SELECT_TUTORIAL:{
164164
target:'#start-new-tutorial',

‎web-app/src/services/xstate-react/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function useMachine<TContext, TEvent extends EventObject>(
8989
// in one place -- this hook's caller.
9090
useEffect(()=>{
9191
Object.assign(service.machine.options.actions,actions)
92-
},[actions])
92+
},[service.machine.options.actions,actions])
9393

9494
// Start service immediately (before mount) if specified in options
9595
if(immediate){
@@ -108,7 +108,7 @@ export function useMachine<TContext, TEvent extends EventObject>(
108108
// Stop the service when the component unmounts
109109
service.stop()
110110
}
111-
},[])
111+
},[service])
112112

113113
return[current,service.send,service]
114114
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp