@@ -21,37 +21,37 @@ const editor = acquireVsCodeApi()
2121
2222// router finds first state match of <Route path='' />
2323const Router = ( { children} :Props ) :React . ReactElement < CloneElementProps > | null => {
24- // const [state, send] = useMachine(createMachine({ editorSend: editor.postMessage }))
25-
26- //// event bus listener
27- // React.useEffect(() => {
28- // const listener = 'message'
29- // window.addEventListener(listener, send)
30- // return () => {
31- // window.removeEventListener(listener, send)
32- // }
33- // }, [])
34-
35- // const childArray = React.Children.toArray(children)
36- // for (const child of childArray) {
37- // const { path } = child.props
38- // let pathMatch
39- // if (typeof path === 'string') {
40- // pathMatch = state.matches(path)
41- // } else if (Array.isArray(path)) {
42- // pathMatch = path.some(p => state.matches(p))
43- // } else {
44- // throw new Error(`Invalid route path ${JSON.stringify(path)}`)
45- // }
46- // if (pathMatch) {
47- // //@ts -ignore
48- // const element = React.cloneElement<CloneElementProps>(child.props.children, { send, context: state.context })
49- // return debuggerWrapper(element, state)
50- // }
51- // }
52- // const message = `No Route matches for ${JSON.stringify(state)}`
53- // onError(new Error(message))
54- // console.warn(message)
24+ const [ state , send ] = useMachine ( createMachine ( { editorSend :editor . postMessage } ) )
25+
26+ // event bus listener
27+ React . useEffect ( ( ) => {
28+ const listener = 'message'
29+ window . addEventListener ( listener , send )
30+ return ( ) => {
31+ window . removeEventListener ( listener , send )
32+ }
33+ } , [ ] )
34+
35+ const childArray = React . Children . toArray ( children )
36+ for ( const child of childArray ) {
37+ const { path} = child . props
38+ let pathMatch
39+ if ( typeof path === 'string' ) {
40+ pathMatch = state . matches ( path )
41+ } else if ( Array . isArray ( path ) ) {
42+ pathMatch = path . some ( p => state . matches ( p ) )
43+ } else {
44+ throw new Error ( `Invalid route path${ JSON . stringify ( path ) } ` )
45+ }
46+ if ( pathMatch ) {
47+ //@ts -ignore
48+ const element = React . cloneElement < CloneElementProps > ( child . props . children , { send, context :state . context } )
49+ return debuggerWrapper ( element , state )
50+ }
51+ }
52+ const message = `No Route matches for${ JSON . stringify ( state ) } `
53+ onError ( new Error ( message ) )
54+ console . warn ( message )
5555return null
5656}
5757