11import * as CR from 'typings'
2- import { assign , Machine , MachineOptions , actions } from 'xstate'
2+ import { assign , Machine , MachineOptions } from 'xstate'
33import editorActions from './actions/editor'
44import commandActions from './actions/command'
55import contextActions from './actions/context'
@@ -72,18 +72,18 @@ export const createMachine = (options: any) => {
7272} ,
7373SelectTutorial :{
7474onEntry :[ 'clearStorage' ] ,
75- id :'start -new-tutorial' ,
75+ id :'select -new-tutorial' ,
7676on :{
7777SELECT_TUTORIAL :{
78- target :'LoadTutorial ' ,
78+ target :'LoadTutorialSummary ' ,
7979actions :[ 'newTutorial' ] ,
8080} ,
8181} ,
8282} ,
8383// TODO move Initialize into New Tutorial setup
84- LoadTutorial :{
84+ LoadTutorialSummary :{
8585invoke :{
86- src :services . loadTutorial ,
86+ src :services . loadTutorialSummary ,
8787onDone :{
8888target :'Summary' ,
8989actions :assign ( {
@@ -102,9 +102,31 @@ export const createMachine = (options: any) => {
102102on :{
103103BACK :'SelectTutorial' ,
104104TUTORIAL_START :{
105- target :'#tutorial' ,
106- actions :[ 'initPosition' , 'initTutorial' ] ,
105+ target :'LoadTutorialData' ,
106+ } ,
107+ } ,
108+ } ,
109+ LoadTutorialData :{
110+ invoke :{
111+ src :services . loadTutorialData ,
112+ onDone :{
113+ target :'SetupNewTutorial' ,
114+ actions :assign ( {
115+ tutorial :( context , event ) => event . data ,
116+ } ) ,
107117} ,
118+ onError :{
119+ target :'Error' ,
120+ actions :assign ( {
121+ error :( context , event ) => event . data ,
122+ } ) ,
123+ } ,
124+ } ,
125+ } ,
126+ SetupNewTutorial :{
127+ onEntry :[ 'configureNewTutorial' , 'initPosition' ] ,
128+ after :{
129+ 0 :'#tutorial' ,
108130} ,
109131} ,
110132ContinueTutorial :{
@@ -224,7 +246,7 @@ export const createMachine = (options: any) => {
224246onEntry :[ 'userTutorialComplete' ] ,
225247on :{
226248SELECT_TUTORIAL :{
227- target :'#start -new-tutorial' ,
249+ target :'#select -new-tutorial' ,
228250actions :[ 'reset' ] ,
229251} ,
230252} ,