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

Commit335a9c7

Browse files
committed
filter events by source=coderoad
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent060ad10 commit335a9c7

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

‎src/channel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class Channel implements Channel {
2020

2121
// receive from webview
2222
publicreceive=async(action:T.Action):Promise<void>=>{
23+
if(action.source!=='coderoad'){
24+
// filter out events from other extensions
25+
return
26+
}
27+
2328
// action may be an object.type or plain string
2429
constactionType:string=typeofaction==='string' ?action :action.type
2530

‎src/services/webview/create.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ const createReactWebView = ({ extensionPath, channel }: ReactWebViewProps): Outp
5656

5757
// Handle messages from the webview
5858
constreceive=channel.receive
59-
constsend=(action:T.Action)=>panel.webview.postMessage(action)
59+
constsend=(action:T.Action)=>
60+
panel.webview.postMessage({
61+
...action,
62+
source:'coderoad',// filter events on client by source. origin is not reliable
63+
})
6064

6165
panel.webview.onDidReceiveMessage(receive,null,disposables)
6266

‎typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface Position {
4949
// current tutorial state
5050

5151
exportinterfaceAction{
52+
source?:'coderoad'// filter received actions by this
5253
type:string
5354
payload?:any
5455
meta?:any

‎web-app/src/services/state/useStateMachine.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ declare let acquireVsCodeApi: any
1616
consteditor=acquireVsCodeApi()
1717
consteditorSend=(action:T.Action)=>{
1818
logger(`TO EXT: "${action.type}"`)
19-
returneditor.postMessage(action)
19+
returneditor.postMessage({
20+
...action,
21+
source:'coderoad',// filter events by source on editor side
22+
})
2023
}
2124

2225
// router finds first state match of <Route path='' />
@@ -31,14 +34,15 @@ const useStateMachine = (): Output => {
3134
// event bus listener
3235
React.useEffect(()=>{
3336
constlistener='message'
34-
//propograte channel event to state machine
37+
//propagate channel event to state machine
3538
consthandler=(event:any)=>{
36-
// ensure events are coming from coderoad webview
37-
if(!event.origin.match(/^vscode-webview/)){
38-
return
39-
}
4039
// NOTE: must call event.data, cannot destructure. VSCode acts odd
4140
constaction=event.data
41+
42+
if(action.source!=='coderoad'){
43+
// filter out events from other extensions
44+
return
45+
}
4246
sendWithLog(action)
4347
}
4448
window.addEventListener(listener,handler)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp