Skip to content

Feature/cleanup #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup client channel
  • Loading branch information
ShMcK committed Jan 29, 2020
commit dec93544883cc26532cf05208befe1b7a79c71d5
14 changes: 12 additions & 2 deletions web-app/src/components/Router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ const Router = ({ children }: Props): React.ReactElement<CloneElementProps> | nu
// event bus listener
React.useEffect(() => {
const listener = 'message'
window.addEventListener(listener, send)
// propograte channel event to state machine
const handler = (action: any) => {
// NOTE: must call event.data, cannot destructure. VSCode acts odd
const event = action.data
// ignore browser events from plugins
if (event.source) {
return
}
send(event)
}
window.addEventListener(listener, handler)
return () => {
window.removeEventListener(listener, send)
window.removeEventListener(listener, handler)
}
}, [])

Expand Down
7 changes: 4 additions & 3 deletions web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as CR from 'typings'
import { assign, Machine, MachineOptions } from 'xstate'
import { assign, Machine, MachineOptions, actions } from 'xstate'
import editorActions from './actions/editor'
import commandActions from './actions/command'
import contextActions from './actions/context'
Expand All @@ -17,8 +17,8 @@ const createOptions = ({ editorSend }: any): MachineOptions<CR.MachineContext, C
delays: {},
})

export const createMachine = (options: any) =>
Machine<CR.MachineContext, CR.MachineStateSchema, CR.MachineEvent>(
export const createMachine = (options: any) => {
return Machine<CR.MachineContext, CR.MachineStateSchema, CR.MachineEvent>(
{
id: 'root',
initial: 'Start',
Expand Down Expand Up @@ -230,3 +230,4 @@ export const createMachine = (options: any) =>
},
createOptions(options),
)
}
15 changes: 7 additions & 8 deletions web-app/src/services/state/services/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,36 @@ export async function authenticate(context: CR.MachineContext): Promise<any> {
},
})
.catch(error => {
onError(error)
// onError(error)
console.log('ERROR: Authentication failed')
console.log(error.message)
// let message
if (error.message.match(/Network error:/)) {
throw {
return Promise.reject({
error: {
title: 'Network Error',
description: 'Make sure you have an Internet connection. Restart and try again',
},
}
})
} else {
throw {
return Promise.reject({
error: {
title: 'Server Error',
description: error.message,
},
}
})
}
})

if (!result || !result.data) {
const error = new Error('Authentication request responded with no data')
console.log(error)
onError(error)
// onError(error)
return
}
const { token } = result.data.editorLogin
console.log(`Token: ${token}`)
// add token to headers
setAuthToken(token)
// pass authenticated action back to state machine
return
return Promise.resolve()
}