@@ -9,12 +9,6 @@ interface TutorialConfig {
99testRunner :G . EnumTestRunner
1010}
1111
12- interface MessageData {
13- tutorial ?:{ id :string }
14- position :CR . Position
15- progress :CR . Progress
16- }
17-
1812export interface TutorialModel {
1913repo :G . TutorialRepo
2014config :TutorialConfig
@@ -28,7 +22,7 @@ export interface TutorialModel {
2822updateProgress ( ) :void
2923nextPosition ( ) :CR . Position
3024hasExisting ( ) :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 {
3731public version :G . TutorialVersion
3832public position :CR . Position
3933public 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+
4739this . repo = { } as G . TutorialRepo
4840this . config = { } as TutorialConfig
4941this . version = { } as G . TutorialVersion
5042this . position = { } as CR . Position
5143this . 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-
6860public async launch ( tutorialId :string ) {
6961const { tutorial} :{ tutorial :G . Tutorial | null } = await api . request ( tutorialQuery , {
7062tutorialId, // TODO: add selection of tutorial id
@@ -97,11 +89,7 @@ class Tutorial implements TutorialModel {
9789
9890console . 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 {
149137this . progress . stages [ stageId ] = true
150138this . 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}
157142public nextPosition = ( ) :CR . Position => {
158143const { levelId, stageId, stepId} = this . position