@@ -5,6 +5,21 @@ import createMachine from './machine'
55// machine interpreter
66// https://xstate.js.org/docs/guides/interpretation.html
77
8+ // convert state into a readable string
9+ const stateToString = ( state :string | object , str :string = '' ) :string => {
10+ if ( typeof state === 'object' ) {
11+ const keys = Object . keys ( state )
12+ if ( keys && keys . length ) {
13+ const key = keys [ 0 ]
14+ return stateToString ( state [ key ] , str . length ?`${ str } .${ key } ` :key )
15+ }
16+ return str
17+ } else if ( typeof state === 'string' ) {
18+ return state
19+ }
20+ return ''
21+ }
22+
823interface Props {
924dispatch :CR . EditorDispatch
1025}
@@ -23,10 +38,8 @@ class StateMachine {
2338this . service = interpret ( machine , this . machineOptions )
2439// logging
2540. onTransition ( state => {
26- // console.log('onTransition', state)
2741if ( state . changed ) {
28- // console.log('next state')
29- // console.log(state.value)
42+ console . log ( `STATE:${ stateToString ( state . value ) } ` )
3043dispatch ( 'coderoad.send_state' , { state :state . value , data :state . context } )
3144} else {
3245dispatch ( 'coderoad.send_data' , { data :state . context } )