Skip to content

Commit

Permalink
fixed set editor ref logic, added check to see if message is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
srietkerk committed Jan 8, 2024
1 parent 4e33d63 commit 2b8e142
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions teachertool/src/services/makecodeEditorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function sendMessageAsync(message?: any) {
makecodeEditorRef!.contentWindow!.postMessage(message, "*");
}

messageQueue.push(message);
if (message) messageQueue.push(message);
if (makecodeEditorRef) {
while (messageQueue.length) {
sendMessageCore(messageQueue.shift());
Expand All @@ -42,12 +42,11 @@ function sendMessageAsync(message?: any) {
}

export function setEditorRef(ref: HTMLIFrameElement | undefined) {
makecodeEditorRef = ref ?? undefined;
window.removeEventListener("message", onMessageReceived);
if (ref) {
makecodeEditorRef = ref;
window.addEventListener("message", onMessageReceived);
} else {
makecodeEditorRef = undefined;
window.removeEventListener("message", onMessageReceived);
sendMessageAsync();
}
}

Expand Down

0 comments on commit 2b8e142

Please sign in to comment.