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

Commit595e181

Browse files
committed
cleanup debugger wrapper
1 parent2dcb5b4 commit595e181

File tree

9 files changed

+95
-50
lines changed

9 files changed

+95
-50
lines changed

‎web-app/src/App.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@ import { ApolloProvider } from '@apollo/react-hooks'
33

44
importclientfrom'./services/apollo'
55
importRoutesfrom'./Routes'
6-
importmessageBusReceiverfrom'./services/channel/receiver'
76

8-
constApp=()=>{
9-
// event bus listener
10-
React.useEffect(messageBusReceiver,[])
11-
12-
return(
13-
<ApolloProviderclient={client}>
14-
<Routes/>
15-
</ApolloProvider>
16-
)
17-
}
7+
constApp=()=>(
8+
<ApolloProviderclient={client}>
9+
<Routes/>
10+
</ApolloProvider>
11+
)
1812

1913
exportdefaultApp

‎web-app/src/Routes.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ const styles = {
2222
consttempSend=(action:any)=>console.log('sent')
2323

2424
constRoutes=()=>{
25-
const[dimensions,setDimensions]=React.useState({
26-
width:window.innerWidth-20,
27-
height:window.innerHeight-20,
28-
})
25+
//const [dimensions, setDimensions] = React.useState({
26+
// width: window.innerWidth - 20,
27+
// height: window.innerHeight - 20,
28+
//})
2929

30-
// solution for windows getting off size
31-
// without adding multiple listeners
32-
React.useEffect(()=>{
33-
constdimensionsInterval=setInterval(()=>{
34-
setDimensions({
35-
width:window.innerWidth-20,
36-
height:window.innerHeight-20,
37-
})
38-
},5000)
39-
return()=>{
40-
clearInterval(dimensionsInterval)
41-
}
42-
},[])
30+
////solution for windows getting off size
31+
////without adding multiple listeners
32+
//React.useEffect(() => {
33+
// const dimensionsInterval = setInterval(() => {
34+
// setDimensions({
35+
// width: window.innerWidth - 20,
36+
// height: window.innerHeight - 20,
37+
// })
38+
// }, 5000)
39+
// return () => {
40+
// clearInterval(dimensionsInterval)
41+
// }
42+
//}, [])
4343

4444
return(
45-
<divstyle={{ ...styles.page, ...dimensions}}>
45+
<divstyle={{ ...styles.page}}>
4646
<Router>
4747
<Routepath="Start.Startup">
4848
<LoadingPagetext="Launching..."/>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import*asReactfrom'react'
2+
importDebuggerfrom'./index'
3+
importstateToStringfrom'./stateToString'
4+
5+
constdebuggerWrapper=(element:React.ReactElement,state:any)=>{
6+
if(process.env.REACT_APP_DEBUG){
7+
return(
8+
<Debuggerstate={stateToString(state.value)}>
9+
{element}
10+
</Debugger>
11+
)
12+
}
13+
returnelement
14+
}
15+
16+
exportdefaultdebuggerWrapper

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,33 @@ import * as React from 'react'
22
import*asCRfrom'typings'
33
import{useMachine}from'@xstate/react'
44
importmachinefrom'../../services/state/machine'
5-
importDebuggerfrom'../Debugger'
5+
66
importRoutefrom'./Route'
7-
importstateToStringfrom'./stateToString'
7+
importdebuggerWrapperfrom'../Debugger/debuggerWrapper'
8+
importmessageBusReceiverfrom'../../services/channel/receiver'
89

910
interfaceProps{
1011
children:any
1112
}
1213

13-
constwrapDebugger=(element:React.ReactElement,state:any)=>{
14-
if(process.env.REACT_APP_DEBUG){
15-
return(
16-
<Debuggerstate={stateToString(state.value)}>
17-
{element}
18-
</Debugger>
19-
)
20-
}
21-
returnelement
22-
}
23-
2414
interfaceCloneElementProps{
2515
send(action:CR.Action):void
2616
}
2717

2818
// router finds first state match of <Route path='' />
2919
constRouter=({ children}:Props):React.ReactElement<CloneElementProps>|null=>{
30-
const[state,send]=useMachine(machine)
20+
const[state,send]=useMachine(machine,{
21+
logger:console.log.bind('XSTATE:')
22+
})
23+
24+
// event bus listener
25+
React.useEffect(messageBusReceiver,[])
3126

3227
constchildArray=React.Children.toArray(children)
3328
for(constchildofchildArray){
3429
if(state.matches(child.props.path)){
3530
constelement=React.cloneElement<CloneElementProps>(child.props.children,{ send})
36-
returnwrapDebugger(element,state)
31+
returndebuggerWrapper(element,state)
3732
}
3833
}
3934
console.warn(`No Route matches for${JSON.stringify(state)}`)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ interface ContainerProps {
2727
}
2828

2929
constNewPageContainer=(props:ContainerProps)=>{
30-
console.log('props',props)
3130
const{ data, loading, error}=useQuery(queryTutorials)
3231
if(loading){
3332
return<Loading/>

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import{Action}from'typings'
2+
import{sendasstateMachineSend}from'xstate'
23

34
declarevaracquireVsCodeApi:any
45

56
//@ts-ignore
67
if(!window.acquireVsCodeApi){
8+
//@ts-ignore
79
require('./mock')
810
}
911

@@ -22,9 +24,23 @@ interface ReceivedEvent {
2224
// Receive from Editor
2325
exportconstreceive=(event:ReceivedEvent):void=>{
2426

25-
constmessage=event.data
26-
console.log('message',message)
27+
constaction=event.data
28+
29+
//@ts-ignore // ignore browser events from plugins
30+
if(action.source){return}
31+
32+
console.log('receive action',action)
2733
// messages from core
34+
switch(action.type){
35+
case'TUTORIAL_LOADED':
36+
// send action to state machine
37+
stateMachineSend('TUTORIAL_LOADED')
38+
console.log(stateMachineSend)
39+
console.log('send action to state machine')
40+
return
41+
default:
42+
console.warn(`Unknown received action${action.type}`,action)
43+
}
2844

2945
// if (message.type === 'SET_DATA') {
3046
// // SET_DATA - set state machine context

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
import{Action}from'typings'
12
import{receive}from'./index'
23

4+
constcreateReceiveEvent=(action:Action)=>({
5+
data:action
6+
})
7+
38
// mock vscode from client side development
49
//@ts-ignore
510
window.acquireVsCodeApi=()=>({
6-
postMessage(event:string){
7-
console.log('postMessage',event)
11+
postMessage(action:Action){
12+
console.log('postMessage',action)
13+
14+
switch(action.type){
15+
case'TUTORIAL_START':
16+
returnsetTimeout(()=>{
17+
constreceiveAction:Action={
18+
type:'TUTORIAL_LOADED'
19+
}
20+
receive(createReceiveEvent(receiveAction))
21+
},1000)
22+
default:
23+
console.warn(`${action.type} not found in post message mock`)
24+
}
825
}
926
})

‎web-app/src/services/state/actions/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import{send}from'xstate'
2+
import*aschannelfrom'../../channel'
23
// import {machine} from '../../extension'
34
// import {cache} from '../../services/apollo'
45
// import {editorDispatch} from '../../services/vscode'
@@ -16,7 +17,14 @@ export default {
1617
returnhasExistingTutorial ?'CONTINUE' :'NEW'
1718
}),
1819
tutorialStart(){
19-
console.log('start')
20+
channel.send({
21+
type:'TUTORIAL_START',
22+
payload:{
23+
tutorial:{
24+
id:'some-tutorial-id'
25+
}
26+
}
27+
})
2028
}
2129
}
2230

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp