Skip to content

Commit c383d2a

Browse files
committed
replace client channel
1 parent f8aa748 commit c383d2a

File tree

17 files changed

+316
-416
lines changed

17 files changed

+316
-416
lines changed

src/channel/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Channel implements Channel {
4040
const onError = (error: T.ErrorMessage) => this.send({ type: 'ERROR', payload: { error } })
4141

4242
switch (actionType) {
43-
case 'ENV_GET':
43+
case 'EDITOR_ENV_GET':
4444
this.send({
4545
type: 'ENV_LOAD',
4646
payload: {

typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export interface MachineStateSchema {
6363
states: {
6464
Startup: {}
6565
Authenticate: {}
66+
Error: {}
6667
NewOrContinue: {}
6768
SelectTutorial: {}
6869
ContinueTutorial: {}

web-app/src/Routes.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const Routes = () => {
2121
<Route path={['Start.Startup', 'Start.Authenticate', 'Start.NewOrContinue']}>
2222
<LoadingPage text="Launching..." context={{} as CR.MachineContext} />
2323
</Route>
24+
<Route path={'Start.Error'}>
25+
<div>Error</div>
26+
</Route>
2427
<Route path="Start.SelectTutorial">
2528
<NewPage send={tempSend} context={{} as CR.MachineContext} />
2629
</Route>

web-app/src/components/Router/index.tsx

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as React from 'react'
22
import * as CR from 'typings'
3-
import channel from '../../services/channel'
4-
import messageBusReceiver from '../../services/channel/receiver'
5-
import machine from '../../services/state/machine'
3+
import { createMachine } from '../../services/state/machine'
64
import { useMachine } from '../../services/xstate-react'
75
import debuggerWrapper from '../Debugger/debuggerWrapper'
86
import Route from './Route'
@@ -17,38 +15,43 @@ interface CloneElementProps {
1715
send(action: CR.Action): void
1816
}
1917

18+
declare let acquireVsCodeApi: any
19+
20+
const editor = acquireVsCodeApi()
21+
2022
// router finds first state match of <Route path='' />
2123
const Router = ({ children }: Props): React.ReactElement<CloneElementProps> | null => {
22-
const [state, send] = useMachine(machine, {
23-
interpreterOptions: {
24-
logger: console.log.bind('XSTATE:'),
25-
},
26-
})
27-
28-
channel.setMachineSend(send)
29-
30-
// event bus listener
31-
React.useEffect(messageBusReceiver, [])
32-
33-
const childArray = React.Children.toArray(children)
34-
for (const child of childArray) {
35-
const { path } = child.props
36-
let pathMatch
37-
if (typeof path === 'string') {
38-
pathMatch = state.matches(path)
39-
} else if (Array.isArray(path)) {
40-
pathMatch = path.some(p => state.matches(p))
41-
} else {
42-
throw new Error(`Invalid route path ${JSON.stringify(path)}`)
43-
}
44-
if (pathMatch) {
45-
const element = React.cloneElement<CloneElementProps>(child.props.children, { send, context: state.context })
46-
return debuggerWrapper(element, state)
47-
}
48-
}
49-
const message = `No Route matches for ${JSON.stringify(state)}`
50-
onError(new Error(message))
51-
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)
5255
return null
5356
}
5457

web-app/src/containers/New/NewPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react'
2+
import * as T from 'typings'
23
import * as G from 'typings/graphql'
34
import { css, jsx } from '@emotion/core'
45
import TutorialList from './TutorialList'
@@ -23,6 +24,7 @@ const styles = {
2324
}
2425

2526
interface Props {
27+
send(action: T.Action): void
2628
tutorialList: G.Tutorial[]
2729
}
2830

@@ -34,7 +36,7 @@ const NewPage = (props: Props) => (
3436
<div css={styles.banner}>
3537
<span>Select a Tutorial to Start</span>
3638
</div>
37-
<TutorialList tutorialList={props.tutorialList} />
39+
<TutorialList tutorialList={props.tutorialList} send={props.send} />
3840
</div>
3941
)
4042

web-app/src/containers/New/TutorialList/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import * as React from 'react'
2+
import * as T from 'typings'
23
import * as G from 'typings/graphql'
3-
import channel from '../../../services/channel'
44
import TutorialItem from './TutorialItem'
55

66
interface Props {
7+
send(action: T.Action): void
78
tutorialList: G.Tutorial[]
89
}
910

1011
const TutorialList = (props: Props) => {
1112
const onSelect = (tutorial: G.Tutorial) => {
12-
channel.machineSend({
13+
props.send({
1314
type: 'TUTORIAL_START',
1415
payload: {
1516
tutorial,

web-app/src/containers/New/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const NewPageContainer = (props: ContainerProps) => {
3131
return null
3232
}
3333

34-
return <NewPage tutorialList={data.tutorials} />
34+
return <NewPage tutorialList={data.tutorials} send={props.send} />
3535
}
3636

3737
export default NewPageContainer

web-app/src/services/channel/index.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

web-app/src/services/channel/mock.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

web-app/src/services/channel/receiver.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)