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;
self.close = () => {
sendEvent("log:hide");
syscall("event.dispatch", "log:hide");
};
syscall("system.getEnv").then((env) => {

View File

@ -1,9 +1,15 @@
document.getElementById("root").addEventListener("click", (e) => {
// console.log("Got click", e.target)
const dataSet = e.target.dataset;
if(dataSet["onclick"]) {
sendEvent("preview:click", dataSet["onclick"]);
} else if(dataSet["pos"]) {
sendEvent("preview:click", JSON.stringify(["pos", dataSet["pos"]]));
if (dataSet["onclick"]) {
syscall("event.dispatch", "preview:click", dataSet["onclick"]).catch((e) =>
console.log("Error", e)
);
} 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) {
window.parent.postMessage({ type: "event", name, args, }, "*");
}
@ -137,12 +138,20 @@ export function Panel({
case "syscall": {
const { id, name, args } = data;
editor.system.localSyscall("core", name, args).then((result) => {
if (!iFrameRef.current?.contentWindow) {
// iFrame already went away
return;
}
iFrameRef.current!.contentWindow!.postMessage({
type: "syscall-response",
id,
result,
});
}).catch((e: any) => {
if (!iFrameRef.current?.contentWindow) {
// iFrame already went away
return;
}
iFrameRef.current!.contentWindow!.postMessage({
type: "syscall-response",
id,