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

Commite31c39b

Browse files
committed
setup editor/machine channel
1 parent595e181 commite31c39b

File tree

5 files changed

+70
-52
lines changed

5 files changed

+70
-52
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import machine from '../../services/state/machine'
55

66
importRoutefrom'./Route'
77
importdebuggerWrapperfrom'../Debugger/debuggerWrapper'
8+
importchannelfrom'../../services/channel'
89
importmessageBusReceiverfrom'../../services/channel/receiver'
910

1011
interfaceProps{
@@ -21,6 +22,8 @@ const Router = ({ children }: Props): React.ReactElement<CloneElementProps>|null
2122
logger:console.log.bind('XSTATE:')
2223
})
2324

25+
channel.setMachineSend(send)
26+
2427
// event bus listener
2528
React.useEffect(messageBusReceiver,[])
2629

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

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,73 @@
11
import{Action}from'typings'
2-
import{sendasstateMachineSend}from'xstate'
32

43
declarevaracquireVsCodeApi:any
54

6-
//@ts-ignore
7-
if(!window.acquireVsCodeApi){
8-
//@ts-ignore
9-
require('./mock')
5+
interfaceReceivedEvent{
6+
data:Action
107
}
118

12-
constchannel=acquireVsCodeApi()
9+
classChannel{
10+
constructor(){
11+
// setup mock if browser only
12+
//@ts-ignore
13+
if(!window.acquireVsCodeApi){
14+
//@ts-ignore
15+
require('./mock')
16+
}
1317

18+
consteditor=acquireVsCodeApi()
19+
this.editorSend=editor.postMessage
20+
}
21+
publicmachineSend=(action:Action|string)=>console.log('machine send')
22+
publiceditorSend=(action:Action)=>console.log('editor send')
1423

15-
// Send to Editor
16-
exportconstsend=(action:Action)=>{
17-
returnchannel.postMessage(action)
18-
}
24+
publicsetMachineSend(send:any){
25+
this.machineSend=send
26+
}
27+
publicreceive(event:ReceivedEvent){
28+
constaction=event.data
1929

20-
interfaceReceivedEvent{
21-
data:Action
22-
}
30+
//@ts-ignore // ignore browser events from plugins
31+
if(action.source){return}
2332

24-
// Receive from Editor
25-
exportconstreceive=(event:ReceivedEvent):void=>{
26-
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)
33-
// 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)
33+
console.log('receive action',action)
34+
// messages from core
35+
switch(action.type){
36+
case'TUTORIAL_LOADED':
37+
// send action to state machine
38+
this.machineSend('TUTORIAL_LOADED')
39+
console.log('send action to state machine')
40+
return
41+
default:
42+
console.warn(`Unknown received action${action.type}`,action)
43+
}
4344
}
44-
45-
// if (message.type === 'SET_DATA') {
46-
// // SET_DATA - set state machine context
47-
// console.log('SET_DATA updated')
48-
// const {progress, position} = message.payload
49-
// if (process.env.REACT_APP_DEBUG) {
50-
// console.log(`Position: ${position.levelId}/${position.stageId}/${position.stepId}`)
51-
// // setDebuggerInfo({ progress, position })
52-
// }
53-
// console.log('set currentTutorial')
54-
// // currentTutorial.set({position, progress})
55-
56-
// }
5745
}
5846

47+
exportdefaultnewChannel()
48+
49+
// Send to Editor
50+
// export const send = (action: Action) => {
51+
// return
52+
// }
53+
54+
55+
56+
// // Receive from Editor
57+
// export const receive = (event: ReceivedEvent): void => {
58+
59+
60+
// // if (message.type === 'SET_DATA') {
61+
// // // SET_DATA - set state machine context
62+
// // console.log('SET_DATA updated')
63+
// // const {progress, position} = message.payload
64+
// // if (process.env.REACT_APP_DEBUG) {
65+
// // console.log(`Position: ${position.levelId}/${position.stageId}/${position.stepId}`)
66+
// // // setDebuggerInfo({ progress, position })
67+
// //}
68+
// // console.log('set currentTutorial')
69+
// // // currentTutorial.set({position, progress})
70+
71+
// //}
72+
// }
73+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{Action}from'typings'
2-
import{receive}from'./index'
2+
importchannelfrom'./index'
33

44
constcreateReceiveEvent=(action:Action)=>({
55
data:action
@@ -17,7 +17,7 @@ window.acquireVsCodeApi = () => ({
1717
constreceiveAction:Action={
1818
type:'TUTORIAL_LOADED'
1919
}
20-
receive(createReceiveEvent(receiveAction))
20+
channel.receive(createReceiveEvent(receiveAction))
2121
},1000)
2222
default:
2323
console.warn(`${action.type} not found in post message mock`)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import{receive}from'./index'
1+
importchannelfrom'./index'
22

33
constmessageBusReceiver=()=>{
44
// update state based on response from editor
55
constlistener='message'
6-
window.addEventListener(listener,receive)
6+
window.addEventListener(listener,channel.receive)
77
return()=>{
8-
window.removeEventListener(listener,receive)
8+
window.removeEventListener(listener,channel.receive)
99
}
1010
}
1111

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{send}from'xstate'
2-
import*aschannelfrom'../../channel'
2+
importchannelfrom'../../channel'
33
// import {machine} from '../../extension'
44
// import {cache} from '../../services/apollo'
55
// import {editorDispatch} from '../../services/vscode'
@@ -17,7 +17,7 @@ export default {
1717
returnhasExistingTutorial ?'CONTINUE' :'NEW'
1818
}),
1919
tutorialStart(){
20-
channel.send({
20+
channel.editorSend({
2121
type:'TUTORIAL_START',
2222
payload:{
2323
tutorial:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp