Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdec9354

Browse files
committed
cleanup client channel
1 parentbe25c8a commitdec9354

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,19 @@ const Router = ({ children }: Props): React.ReactElement<CloneElementProps> | nu
2626
// event bus listener
2727
React.useEffect(()=>{
2828
constlistener='message'
29-
window.addEventListener(listener,send)
29+
// propograte channel event to state machine
30+
consthandler=(action:any)=>{
31+
// NOTE: must call event.data, cannot destructure. VSCode acts odd
32+
constevent=action.data
33+
// ignore browser events from plugins
34+
if(event.source){
35+
return
36+
}
37+
send(event)
38+
}
39+
window.addEventListener(listener,handler)
3040
return()=>{
31-
window.removeEventListener(listener,send)
41+
window.removeEventListener(listener,handler)
3242
}
3343
},[])
3444

‎web-app/src/services/state/machine.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asCRfrom'typings'
2-
import{assign,Machine,MachineOptions}from'xstate'
2+
import{assign,Machine,MachineOptions,actions}from'xstate'
33
importeditorActionsfrom'./actions/editor'
44
importcommandActionsfrom'./actions/command'
55
importcontextActionsfrom'./actions/context'
@@ -17,8 +17,8 @@ const createOptions = ({ editorSend }: any): MachineOptions<CR.MachineContext, C
1717
delays:{},
1818
})
1919

20-
exportconstcreateMachine=(options:any)=>
21-
Machine<CR.MachineContext,CR.MachineStateSchema,CR.MachineEvent>(
20+
exportconstcreateMachine=(options:any)=>{
21+
returnMachine<CR.MachineContext,CR.MachineStateSchema,CR.MachineEvent>(
2222
{
2323
id:'root',
2424
initial:'Start',
@@ -230,3 +230,4 @@ export const createMachine = (options: any) =>
230230
},
231231
createOptions(options),
232232
)
233+
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,36 @@ export async function authenticate(context: CR.MachineContext): Promise<any> {
2929
},
3030
})
3131
.catch(error=>{
32-
onError(error)
32+
//onError(error)
3333
console.log('ERROR: Authentication failed')
3434
console.log(error.message)
3535
// let message
3636
if(error.message.match(/Networkerror:/)){
37-
throw{
37+
returnPromise.reject({
3838
error:{
3939
title:'Network Error',
4040
description:'Make sure you have an Internet connection. Restart and try again',
4141
},
42-
}
42+
})
4343
}else{
44-
throw{
44+
returnPromise.reject({
4545
error:{
4646
title:'Server Error',
4747
description:error.message,
4848
},
49-
}
49+
})
5050
}
5151
})
5252

5353
if(!result||!result.data){
5454
consterror=newError('Authentication request responded with no data')
5555
console.log(error)
56-
onError(error)
56+
//onError(error)
5757
return
5858
}
5959
const{ token}=result.data.editorLogin
60-
console.log(`Token:${token}`)
6160
// add token to headers
6261
setAuthToken(token)
6362
// pass authenticated action back to state machine
64-
return
63+
returnPromise.resolve()
6564
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp