2
2
// https://github.com/codesandbox/codesandbox-client/blob/master/packages/codesandbox-api/src/dispatcher/index.ts
3
3
4
4
const frames : {
5
- [ key : number ] : { frame : Window | null , origin : string }
5
+ [ key : number ] : { frame : Window | null ; origin : string } ;
6
6
} = { } ;
7
7
let frameIndex = 1 ;
8
8
@@ -13,7 +13,7 @@ export const MessageTypes = {
13
13
FILES : 'FILES' ,
14
14
SKETCH : 'SKETCH' ,
15
15
REGISTER : 'REGISTER' ,
16
- EXECUTE : 'EXECUTE' ,
16
+ EXECUTE : 'EXECUTE'
17
17
// eslint-disable-next-line prettier/prettier
18
18
} as const ;
19
19
@@ -26,8 +26,8 @@ export type MessageType = typeof MessageTypes[keyof typeof MessageTypes];
26
26
* - payload: additional data for that message type
27
27
*/
28
28
export type Message = {
29
- type : MessageType ,
30
- payload ?: any
29
+ type : MessageType ;
30
+ payload ?: any ;
31
31
} ;
32
32
33
33
let listener : ( ( message : Message ) => void ) | null = null ;
@@ -57,7 +57,7 @@ function notifyListener(message: Message): void {
57
57
function notifyFrames ( message : Message ) {
58
58
const rawMessage = JSON . parse ( JSON . stringify ( message ) ) ;
59
59
Object . values ( frames ) . forEach ( ( frameObj ) => {
60
- const { frame, origin } = frameObj
60
+ const { frame, origin } = frameObj ;
61
61
if ( frame && frame . postMessage ) {
62
62
frame . postMessage ( rawMessage , origin ) ;
63
63
}
@@ -70,10 +70,6 @@ function notifyFrames(message: Message) {
70
70
*/
71
71
export function dispatchMessage ( message : Message | undefined | null ) : void {
72
72
if ( ! message ) return ;
73
-
74
- // maybe one day i will understand why in the codesandbox
75
- // code they leave notifyListeners in here?
76
- // notifyListener(message);
77
73
notifyFrames ( message ) ;
78
74
}
79
75
@@ -89,9 +85,6 @@ export function listen(callback: (message: Message) => void): () => void {
89
85
90
86
function eventListener ( e : MessageEvent ) {
91
87
const { data } = e ;
92
-
93
- // should also store origin of parent? idk
94
- // if (data && e.origin === origin) {
95
88
if ( data ) {
96
89
notifyListener ( data ) ;
97
90
}
0 commit comments