Skip to content

Commit 9257205

Browse files
committed
cleanup event typings
1 parent b482ef8 commit 9257205

File tree

12 files changed

+42
-41
lines changed

12 files changed

+42
-41
lines changed

src/channel/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as CR from 'typings'
22
import * as G from 'typings/graphql'
3-
import { EditorEvent, ClientEvent } from 'typings/events'
3+
import { EditorEvents, ClientEvents } from 'typings/events'
44
import * as vscode from 'vscode'
55
import saveCommit from '../actions/saveCommit'
66
import setupActions from '../actions/setupActions'
@@ -11,18 +11,18 @@ import logger from '../services/logger'
1111
import Context from './context'
1212

1313
interface Channel {
14-
receive(action: EditorEvent): Promise<void>
15-
send(action: ClientEvent): Promise<void>
14+
receive(action: EditorEvents): Promise<void>
15+
send(action: ClientEvents): Promise<void>
1616
}
1717

1818
interface ChannelProps {
19-
postMessage: (action: ClientEvent) => Thenable<boolean>
19+
postMessage: (action: ClientEvents) => Thenable<boolean>
2020
workspaceState: vscode.Memento
2121
workspaceRoot: vscode.WorkspaceFolder
2222
}
2323

2424
class Channel implements Channel {
25-
private postMessage: (action: ClientEvent) => Thenable<boolean>
25+
private postMessage: (action: ClientEvents) => Thenable<boolean>
2626
private workspaceState: vscode.Memento
2727
private workspaceRoot: vscode.WorkspaceFolder
2828
private context: Context
@@ -35,7 +35,7 @@ class Channel implements Channel {
3535
}
3636

3737
// receive from webview
38-
public receive = async (action: EditorEvent) => {
38+
public receive = async (action: EditorEvents) => {
3939
// action may be an object.type or plain string
4040
const actionType: string = typeof action === 'string' ? action : action.type
4141
const onError = (error: CR.ErrorMessage) => this.send({ type: 'ERROR', payload: { error } })
@@ -98,7 +98,7 @@ class Channel implements Channel {
9898
if (!tutorialContinue) {
9999
throw new Error('Invalid tutorial to continue')
100100
}
101-
const continueConfig: T.TutorialConfig = tutorialContinue.version.data.config
101+
const continueConfig: CR.TutorialConfig = tutorialContinue.version.data.config
102102
tutorialConfig(
103103
{
104104
config: continueConfig,
@@ -127,7 +127,7 @@ class Channel implements Channel {
127127
}
128128
}
129129
// send to webview
130-
public send = async (action: ClientEvent) => {
130+
public send = async (action: ClientEvents) => {
131131
// action may be an object.type or plain string
132132
const actionType: string = typeof action === 'string' ? action : action.type
133133
switch (actionType) {

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"emitDecoratorMetadata": true,
2121
"paths": {
2222
"typings": ["../typings/index.d.ts"],
23-
"typings/graphql": ["../typings/graphql.d.ts"]
23+
"typings/graphql": ["../typings/graphql.d.ts"],
24+
"typings/events": ["../typings/events.d.ts"]
2425
},
2526
"allowJs": true,
2627
"removeComments": true

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import * as React from 'react'
2+
import { ClientEvents } from 'typings/events'
23
import channel from '../../services/channel'
34
import messageBusReceiver from '../../services/channel/receiver'
45
import machine from '../../services/state/machine'
56
import { useMachine } from '../../services/xstate-react'
67
import debuggerWrapper from '../Debugger/debuggerWrapper'
78
import Route from './Route'
89
import onError from '../../services/sentry/onError'
9-
import { MachineContext, MachineEvent } from '../../services/state/machine'
10+
import { MachineContext } from '../../services/state/machine'
1011

1112
interface Props {
1213
children: any
1314
}
1415

1516
interface CloneElementProps {
1617
context: MachineContext
17-
send(action: MachineEvent): void
18+
send(action: ClientEvents): void
1819
}
1920

2021
// TODO: rewrite router, logic is messy

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react'
2+
import { ClientEvents } from 'typings/events'
23
import * as G from 'typings/graphql'
3-
import { MachineContext, MachineEvent } from '../../services/state/selectTutorial'
4+
import { MachineContext } from '../../services/state/selectTutorial'
45
import { css, jsx } from '@emotion/core'
56
import Button from '../../components/Button'
67
import Card from '../../components/Card'
@@ -48,7 +49,7 @@ export const ContinuePage = (props: Props) => (
4849

4950
interface ContainerProps {
5051
context: MachineContext
51-
send(action: MachineEvent): void
52+
send(action: ClientEvents): void
5253
}
5354

5455
const ContinuePageContainer = ({ context, send }: ContainerProps) => {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { useQuery } from '@apollo/react-hooks'
22
import * as React from 'react'
3+
import { ClientEvents } from 'typings/events'
34
import * as G from 'typings/graphql'
4-
import { MachineContext, MachineEvent } from '../../services/state/selectTutorial'
5+
import { MachineContext } from '../../services/state/selectTutorial'
56
import ErrorView from '../../components/Error'
67
import queryTutorials from '../../services/apollo/queries/tutorials'
78
import LoadingPage from '../LoadingPage'
89
import NewPage from './NewPage'
910

1011
interface ContainerProps {
11-
send(action: MachineEvent): void
12+
send(action: ClientEvents): void
1213
context: MachineContext
1314
}
1415

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { useQuery } from '@apollo/react-hooks'
22
import * as React from 'react'
33
import * as G from 'typings/graphql'
4+
import { ClientEvents } from 'typings/events'
45
import ErrorView from '../../components/Error'
56
import queryTutorial from '../../services/apollo/queries/tutorial'
67
import OverviewPage from './OverviewPage'
7-
import { MachineContext, MachineEvent } from '../../services/state/selectTutorial'
8+
import { MachineContext } from '../../services/state/selectTutorial'
89

910
interface PageProps {
1011
context: MachineContext
11-
send(action: MachineEvent): void
12+
send(action: ClientEvents): void
1213
}
1314

1415
interface TutorialData {

web-app/src/containers/Tutorial/CompletedPage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react'
2-
import { MachineContext, MachineEvent } from '../../services/state/playTutorial'
2+
import { ClientEvents } from 'typings/events'
3+
import { MachineContext } from '../../services/state/playTutorial'
34
import { css, jsx } from '@emotion/core'
45
import Button from '../../components/Button'
56

@@ -11,7 +12,7 @@ const styles = {
1112

1213
interface Props {
1314
context: MachineContext
14-
send(action: MachineEvent): void
15+
send(action: ClientEvents): void
1516
}
1617

1718
const CompletedPage = (props: Props) => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as CR from 'typings'
22
import * as G from 'typings/graphql'
3-
import { EditorEvent, ClientEvent } from 'typings/events'
3+
import { EditorEvents, ClientEvents } from 'typings/events'
44

55
declare let acquireVsCodeApi: any
66

77
interface ReceivedEvent {
8-
data: ClientEvent
8+
data: ClientEvents
99
}
1010

1111
class Channel {
@@ -23,10 +23,10 @@ class Channel {
2323
this.editorSend = editor.postMessage
2424
}
2525

26-
public machineSend = (event: ClientEvent) => {
26+
public machineSend = (event: ClientEvents) => {
2727
/* implemented by `setMachineSend` in router on startup */
2828
}
29-
public editorSend = (event: EditorEvent) => {
29+
public editorSend = (event: EditorEvents) => {
3030
/* */
3131
}
3232

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { Action } from 'typings'
1+
import { ClientEvents } from 'typings/events'
22
import channel from './index'
33

4-
const createReceiveEvent = (action: Action) => ({
4+
const createReceiveEvent = (action: ClientEvents) => ({
55
data: action,
66
})
77

88
// mock vscode from client side development
99
// @ts-ignore
1010
window.acquireVsCodeApi = () => ({
11-
postMessage(action: Action) {
11+
postMessage(action: ClientEvents) {
1212
switch (action.type) {
1313
case 'TUTORIAL_START':
1414
return setTimeout(() => {
15-
const receiveAction: Action = {
15+
const receiveAction: ClientEvents = {
1616
type: 'TUTORIAL_LOADED',
1717
}
1818
channel.receive(createReceiveEvent(receiveAction))
1919
}, 1000)
2020
case 'TEST_RUN':
2121
return setTimeout(() => {
22-
const receiveAction: Action = {
22+
const receiveAction: ClientEvents = {
2323
type: 'TEST_PASS',
2424
payload: action.payload,
2525
}

web-app/src/services/state/authenticate/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as CR from 'typings'
22
import * as G from 'typings/graphql'
3-
import { AuthenticateEvent, EnvGetEvent } from 'typings/events'
3+
import { AuthenticateEvents, EnvGetEvent } from 'typings/events'
44
import { assign, ActionFunctionMap } from 'xstate'
55
import client from '../../apollo'
66
import { setAuthToken } from '../../apollo/auth'
@@ -22,7 +22,7 @@ interface AuthenticateVariables {
2222
editor: 'VSCODE'
2323
}
2424

25-
const actions: ActionFunctionMap<MachineContext, AuthenticateEvent> = {
25+
const actions: ActionFunctionMap<MachineContext, AuthenticateEvents> = {
2626
// @ts-ignore
2727
setEnv: assign({
2828
env: (context: MachineContext, event: EnvGetEvent): CR.Environment => ({

web-app/src/services/state/authenticate/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as CR from 'typings'
2-
import { AuthenticateEvent } from 'typings/events'
2+
import { AuthenticateEvents } from 'typings/events'
33
import { Machine } from 'xstate'
44
import actions from './actions'
55

@@ -20,7 +20,7 @@ const options = {
2020
actions,
2121
}
2222

23-
export const authenticateMachine = Machine<MachineContext, StateSchema, AuthenticateEvent>(
23+
export const authenticateMachine = Machine<MachineContext, StateSchema, AuthenticateEvents>(
2424
{
2525
id: 'authenticate',
2626
context: {

web-app/src/services/state/selectTutorial/actions.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ interface TutorialDataVariables {
1919
}
2020

2121
const actionMap: ActionFunctionMap<MachineContext, Event.SelectTutorialEvents> = {
22-
loadEnv(): void {
23-
channel.editorSend({
24-
type: 'ENV_GET',
25-
})
26-
},
2722
loadStoredTutorial(): void {
2823
// send message to editor to see if there is existing tutorial progress
2924
// in local storage on the editor
@@ -81,10 +76,10 @@ const actionMap: ActionFunctionMap<MachineContext, Event.SelectTutorialEvents> =
8176
// },
8277
// })
8378
// },
84-
initPositionAndProgress: assign((context: MachineContext, event: Event.LoadTutorialEvent) => ({
85-
position: selectors.initialPosition(event.payload),
86-
progress: selectors.defaultProgress(),
87-
})),
79+
// initPositionAndProgress: assign((context: MachineContext, event: Event.LoadTutorialEvent) => ({
80+
// position: selectors.initialPosition(event.payload),
81+
// progress: selectors.defaultProgress(),
82+
// })),
8883
clearStorage(): void {
8984
channel.editorSend({ type: 'TUTORIAL_CLEAR' })
9085
},

0 commit comments

Comments
 (0)