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

Commitc383d2a

Browse files
committed
replace client channel
1 parentf8aa748 commitc383d2a

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
constonError=(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
<Routepath={['Start.Startup','Start.Authenticate','Start.NewOrContinue']}>
2222
<LoadingPagetext="Launching..."context={{}asCR.MachineContext}/>
2323
</Route>
24+
<Routepath={'Start.Error'}>
25+
<div>Error</div>
26+
</Route>
2427
<Routepath="Start.SelectTutorial">
2528
<NewPagesend={tempSend}context={{}asCR.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*asReactfrom'react'
22
import*asCRfrom'typings'
3-
importchannelfrom'../../services/channel'
4-
importmessageBusReceiverfrom'../../services/channel/receiver'
5-
importmachinefrom'../../services/state/machine'
3+
import{createMachine}from'../../services/state/machine'
64
import{useMachine}from'../../services/xstate-react'
75
importdebuggerWrapperfrom'../Debugger/debuggerWrapper'
86
importRoutefrom'./Route'
@@ -17,38 +15,43 @@ interface CloneElementProps {
1715
send(action:CR.Action):void
1816
}
1917

18+
declareletacquireVsCodeApi:any
19+
20+
consteditor=acquireVsCodeApi()
21+
2022
// router finds first state match of <Route path='' />
2123
constRouter=({ 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-
constchildArray=React.Children.toArray(children)
34-
for(constchildofchildArray){
35-
const{ path}=child.props
36-
letpathMatch
37-
if(typeofpath==='string'){
38-
pathMatch=state.matches(path)
39-
}elseif(Array.isArray(path)){
40-
pathMatch=path.some(p=>state.matches(p))
41-
}else{
42-
thrownewError(`Invalid route path${JSON.stringify(path)}`)
43-
}
44-
if(pathMatch){
45-
constelement=React.cloneElement<CloneElementProps>(child.props.children,{ send,context:state.context})
46-
returndebuggerWrapper(element,state)
47-
}
48-
}
49-
constmessage=`No Route matches for${JSON.stringify(state)}`
50-
onError(newError(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
returnnull
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*asReactfrom'react'
2+
import*asTfrom'typings'
23
import*asGfrom'typings/graphql'
34
import{css,jsx}from'@emotion/core'
45
importTutorialListfrom'./TutorialList'
@@ -23,6 +24,7 @@ const styles = {
2324
}
2425

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

@@ -34,7 +36,7 @@ const NewPage = (props: Props) => (
3436
<divcss={styles.banner}>
3537
<span>Select a Tutorial to Start</span>
3638
</div>
37-
<TutorialListtutorialList={props.tutorialList}/>
39+
<TutorialListtutorialList={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*asReactfrom'react'
2+
import*asTfrom'typings'
23
import*asGfrom'typings/graphql'
3-
importchannelfrom'../../../services/channel'
44
importTutorialItemfrom'./TutorialItem'
55

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

1011
constTutorialList=(props:Props)=>{
1112
constonSelect=(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
returnnull
3232
}
3333

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

3737
exportdefaultNewPageContainer

‎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.

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

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

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import*asCRfrom'typings'
22
import*asGfrom'typings/graphql'
3-
import{assign,send}from'xstate'
3+
import{assign,send,ActionFunctionMap}from'xstate'
44
import*asselectorsfrom'../../selectors'
55
importonErrorfrom'../../../services/sentry/onError'
66

7-
exportdefault{
7+
constcontextActions:ActionFunctionMap<CR.MachineContext,CR.MachineEvent>={
8+
//@ts-ignore
89
setEnv:assign({
910
env:(context:CR.MachineContext,event:CR.MachineEvent)=>{
1011
return{
@@ -13,6 +14,7 @@ export default {
1314
}
1415
},
1516
}),
17+
//@ts-ignore
1618
continueTutorial:assign({
1719
tutorial:(context:CR.MachineContext,event:CR.MachineEvent)=>{
1820
returnevent.payload.tutorial
@@ -24,6 +26,7 @@ export default {
2426
returnevent.payload.position
2527
},
2628
}),
29+
//@ts-ignore
2730
newTutorial:assign({
2831
tutorial:(context:CR.MachineContext,event:CR.MachineEvent):any=>{
2932
returnevent.payload.tutorial
@@ -32,6 +35,7 @@ export default {
3235
return{levels:{},steps:{},complete:false}
3336
},
3437
}),
38+
//@ts-ignore
3539
initTutorial:assign({
3640
// loads complete tutorial
3741
tutorial:(context:CR.MachineContext,event:CR.MachineEvent):any=>{
@@ -201,6 +205,7 @@ export default {
201205
}
202206
},
203207
),
208+
//@ts-ignore
204209
reset:assign({
205210
tutorial(){
206211
returnnull
@@ -221,3 +226,5 @@ export default {
221226
},
222227
}),
223228
}
229+
230+
exportdefaultcontextActions

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp