@@ -9,12 +9,6 @@ interface TutorialConfig {
99 testRunner : G . EnumTestRunner
1010}
1111
12- interface MessageData {
13- tutorial ?: { id : string }
14- position : CR . Position
15- progress : CR . Progress
16- }
17-
1812export interface TutorialModel {
1913 repo : G . TutorialRepo
2014 config : TutorialConfig
@@ -28,7 +22,7 @@ export interface TutorialModel {
2822 updateProgress ( ) : void
2923 nextPosition ( ) : CR . Position
3024 hasExisting ( ) : Promise < boolean >
31- setClientDispatch ( editorDispatch : CR . EditorDispatch ) : void
25+ syncClient ( ) : void
3226}
3327
3428class Tutorial implements TutorialModel {
@@ -37,19 +31,21 @@ class Tutorial implements TutorialModel {
3731 public version : G . TutorialVersion
3832 public position : CR . Position
3933 public progress : CR . Progress
40- private clientDispatch : ( props : MessageData ) => void
34+ public syncClient : ( ) => void
4135
42- constructor ( ) {
36+ constructor ( editorDispatch : CR . EditorDispatch ) {
4337 // initialize types, will be assigned when tutorial is selected
44- this . clientDispatch = ( props : MessageData ) => {
45- throw new Error ( 'Tutorial client dispatch yet initialized' )
46- }
38+
4739 this . repo = { } as G . TutorialRepo
4840 this . config = { } as TutorialConfig
4941 this . version = { } as G . TutorialVersion
5042 this . position = { } as CR . Position
5143 this . progress = { } as CR . Progress
52-
44+ this . syncClient = ( ) => editorDispatch ( 'coderoad.send_data' , {
45+ tutorial : { id : this . version . tutorialId } ,
46+ progress : this . progress ,
47+ position : this . position ,
48+ } )
5349 // Promise.all([
5450 // storage.getTutorial(),
5551 // storage.getProgress(),
@@ -61,10 +57,6 @@ class Tutorial implements TutorialModel {
6157
6258 }
6359
64- public setClientDispatch ( editorDispatch : CR . EditorDispatch ) {
65- this . clientDispatch = ( { progress, position} : MessageData ) => editorDispatch ( 'coderoad.send_data' , { progress, position} )
66- }
67-
6860 public async launch ( tutorialId : string ) {
6961 const { tutorial} : { tutorial : G . Tutorial | null } = await api . request ( tutorialQuery , {
7062 tutorialId, // TODO: add selection of tutorial id
@@ -97,11 +89,7 @@ class Tutorial implements TutorialModel {
9789
9890 console . log ( 'this.position' , JSON . stringify ( this . position ) )
9991
100- this . clientDispatch ( {
101- tutorial : { id : tutorial . id } ,
102- position : this . position ,
103- progress : this . progress
104- } )
92+ this . syncClient ( )
10593
10694 // set tutorial, position, progress locally
10795 // TODO: base position off of progress
@@ -149,10 +137,7 @@ class Tutorial implements TutorialModel {
149137 this . progress . stages [ stageId ] = true
150138 this . progress . steps [ stepId ] = true
151139
152- this . clientDispatch ( {
153- progress : this . progress ,
154- position : this . position , // TODO: calculate next position
155- } )
140+ this . syncClient ( )
156141 }
157142 public nextPosition = ( ) : CR . Position => {
158143 const { levelId, stageId, stepId} = this . position
0 commit comments