@@ -4,7 +4,7 @@ import { createMachine } from '../../services/state/machine'
44import { useMachine } from '../../services/xstate-react'
55import Route from './Route'
66import onError from '../../services/sentry/onError'
7- import { LOG_STATE } from '../../environment '
7+ import logger from '../../services/logger '
88
99interface Output {
1010 context : T . MachineContext
@@ -16,27 +16,30 @@ interface Output {
1616declare let acquireVsCodeApi : any
1717
1818const editor = acquireVsCodeApi ( )
19+ const editorSend = ( action : T . Action ) => {
20+ logger ( `CLIENT TO EXT: "${ action . type } "` )
21+ return editor . postMessage ( action )
22+ }
1923
2024// router finds first state match of <Route path='' />
2125const useRouter = ( ) : Output => {
22- const [ state , send ] = useMachine < T . MachineContext , any > ( createMachine ( { editorSend : editor . postMessage } ) )
26+ const [ state , send ] = useMachine < T . MachineContext , any > ( createMachine ( { editorSend } ) )
2327
24- if ( LOG_STATE ) {
25- console . log ( JSON . stringify ( state . value ) )
26- }
28+ logger ( `STATE: ${ JSON . stringify ( state . value ) } ` )
2729
2830 // event bus listener
2931 React . useEffect ( ( ) => {
3032 const listener = 'message'
3133 // propograte channel event to state machine
32- const handler = ( action : any ) => {
34+ const handler = ( event : any ) => {
3335 // NOTE: must call event.data, cannot destructure. VSCode acts odd
34- const event = action . data
36+ const action = event . data
3537 // ignore browser events from plugins
36- if ( event . source ) {
38+ if ( action . source ) {
3739 return
3840 }
39- send ( event )
41+ logger ( `CLIENT RECEIVED: "${ action . type } "` )
42+ send ( action )
4043 }
4144 window . addEventListener ( listener , handler )
4245 return ( ) => {
0 commit comments