Transition from sendEvent to syscall event.dispatch

pull/320/head
Zef Hemel 2023-01-16 11:06:07 +01:00
parent ef7830662e
commit 882f157cf1
3 changed files with 21 additions and 6 deletions

View File

@ -60,7 +60,7 @@ export async function showLogsCommand() {
serverDiv.scrollTop = serverDiv.scrollHeight; serverDiv.scrollTop = serverDiv.scrollHeight;
self.close = () => { self.close = () => {
sendEvent("log:hide"); syscall("event.dispatch", "log:hide");
}; };
syscall("system.getEnv").then((env) => { syscall("system.getEnv").then((env) => {

View File

@ -1,9 +1,15 @@
document.getElementById("root").addEventListener("click", (e) => { document.getElementById("root").addEventListener("click", (e) => {
// console.log("Got click", e.target) // console.log("Got click", e.target)
const dataSet = e.target.dataset; const dataSet = e.target.dataset;
if(dataSet["onclick"]) { if (dataSet["onclick"]) {
sendEvent("preview:click", dataSet["onclick"]); syscall("event.dispatch", "preview:click", dataSet["onclick"]).catch((e) =>
} else if(dataSet["pos"]) { console.log("Error", e)
sendEvent("preview:click", JSON.stringify(["pos", dataSet["pos"]])); );
} else if (dataSet["pos"]) {
syscall(
"event.dispatch",
"preview:click",
JSON.stringify(["pos", dataSet["pos"]])
).catch((e) => console.log("Error", e));
} }
}) });

View File

@ -62,6 +62,7 @@ window.addEventListener("message", (message) => {
} }
}); });
// DEPRECATED: Use syscall("event.dispatch", ...) instead
function sendEvent(name, ...args) { function sendEvent(name, ...args) {
window.parent.postMessage({ type: "event", name, args, }, "*"); window.parent.postMessage({ type: "event", name, args, }, "*");
} }
@ -137,12 +138,20 @@ export function Panel({
case "syscall": { case "syscall": {
const { id, name, args } = data; const { id, name, args } = data;
editor.system.localSyscall("core", name, args).then((result) => { editor.system.localSyscall("core", name, args).then((result) => {
if (!iFrameRef.current?.contentWindow) {
// iFrame already went away
return;
}
iFrameRef.current!.contentWindow!.postMessage({ iFrameRef.current!.contentWindow!.postMessage({
type: "syscall-response", type: "syscall-response",
id, id,
result, result,
}); });
}).catch((e: any) => { }).catch((e: any) => {
if (!iFrameRef.current?.contentWindow) {
// iFrame already went away
return;
}
iFrameRef.current!.contentWindow!.postMessage({ iFrameRef.current!.contentWindow!.postMessage({
type: "syscall-response", type: "syscall-response",
id, id,