File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -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 {
924 dispatch : CR . EditorDispatch
1025}
@@ -23,10 +38,8 @@ class StateMachine {
2338 this . service = interpret ( machine , this . machineOptions )
2439 // logging
2540 . onTransition ( state => {
26- // console.log('onTransition', state)
2741 if ( state . changed ) {
28- // console.log('next state')
29- // console.log(state.value)
42+ console . log ( `STATE: ${ stateToString ( state . value ) } ` )
3043 dispatch ( 'coderoad.send_state' , { state : state . value , data : state . context } )
3144 } else {
3245 dispatch ( 'coderoad.send_data' , { data : state . context } )
You can’t perform that action at this time.
0 commit comments