|
@@ -260,11 +260,15 @@ export const applyEvent = async (event, socket) => {
|
|
try {
|
|
try {
|
|
const eval_result = event.payload.function();
|
|
const eval_result = event.payload.function();
|
|
if (event.payload.callback) {
|
|
if (event.payload.callback) {
|
|
- if (!!eval_result && typeof eval_result.then === "function") {
|
|
|
|
- event.payload.callback(await eval_result);
|
|
|
|
- } else {
|
|
|
|
- event.payload.callback(eval_result);
|
|
|
|
- }
|
|
|
|
|
|
+ const final_result =
|
|
|
|
+ !!eval_result && typeof eval_result.then === "function"
|
|
|
|
+ ? await eval_result
|
|
|
|
+ : eval_result;
|
|
|
|
+ const callback =
|
|
|
|
+ typeof event.payload.callback === "string"
|
|
|
|
+ ? eval(event.payload.callback)
|
|
|
|
+ : event.payload.callback;
|
|
|
|
+ callback(final_result);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log("_call_function", e);
|
|
console.log("_call_function", e);
|
|
@@ -283,11 +287,15 @@ export const applyEvent = async (event, socket) => {
|
|
: eval(event.payload.function)();
|
|
: eval(event.payload.function)();
|
|
|
|
|
|
if (event.payload.callback) {
|
|
if (event.payload.callback) {
|
|
- if (!!eval_result && typeof eval_result.then === "function") {
|
|
|
|
- eval(event.payload.callback)(await eval_result);
|
|
|
|
- } else {
|
|
|
|
- eval(event.payload.callback)(eval_result);
|
|
|
|
- }
|
|
|
|
|
|
+ const final_result =
|
|
|
|
+ !!eval_result && typeof eval_result.then === "function"
|
|
|
|
+ ? await eval_result
|
|
|
|
+ : eval_result;
|
|
|
|
+ const callback =
|
|
|
|
+ typeof event.payload.callback === "string"
|
|
|
|
+ ? eval(event.payload.callback)
|
|
|
|
+ : event.payload.callback;
|
|
|
|
+ callback(final_result);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log("_call_script", e);
|
|
console.log("_call_script", e);
|
|
@@ -364,7 +372,7 @@ export const queueEvents = async (events, socket, prepend) => {
|
|
),
|
|
),
|
|
];
|
|
];
|
|
}
|
|
}
|
|
- event_queue.push(...events);
|
|
|
|
|
|
+ event_queue.push(...events.filter((e) => e !== undefined && e !== null));
|
|
await processEvent(socket.current);
|
|
await processEvent(socket.current);
|
|
};
|
|
};
|
|
|
|
|
|
@@ -750,11 +758,13 @@ export const useEventLoop = (
|
|
|
|
|
|
// Function to add new events to the event queue.
|
|
// Function to add new events to the event queue.
|
|
const addEvents = (events, args, event_actions) => {
|
|
const addEvents = (events, args, event_actions) => {
|
|
|
|
+ const _events = events.filter((e) => e !== undefined && e !== null);
|
|
|
|
+
|
|
if (!(args instanceof Array)) {
|
|
if (!(args instanceof Array)) {
|
|
args = [args];
|
|
args = [args];
|
|
}
|
|
}
|
|
|
|
|
|
- event_actions = events.reduce(
|
|
|
|
|
|
+ event_actions = _events.reduce(
|
|
(acc, e) => ({ ...acc, ...e.event_actions }),
|
|
(acc, e) => ({ ...acc, ...e.event_actions }),
|
|
event_actions ?? {},
|
|
event_actions ?? {},
|
|
);
|
|
);
|
|
@@ -767,7 +777,7 @@ export const useEventLoop = (
|
|
if (event_actions?.stopPropagation && _e?.stopPropagation) {
|
|
if (event_actions?.stopPropagation && _e?.stopPropagation) {
|
|
_e.stopPropagation();
|
|
_e.stopPropagation();
|
|
}
|
|
}
|
|
- const combined_name = events.map((e) => e.name).join("+++");
|
|
|
|
|
|
+ const combined_name = _events.map((e) => e.name).join("+++");
|
|
if (event_actions?.temporal) {
|
|
if (event_actions?.temporal) {
|
|
if (!socket.current || !socket.current.connected) {
|
|
if (!socket.current || !socket.current.connected) {
|
|
return; // don't queue when the backend is not connected
|
|
return; // don't queue when the backend is not connected
|
|
@@ -783,11 +793,11 @@ export const useEventLoop = (
|
|
// If debounce is used, queue the events after some delay
|
|
// If debounce is used, queue the events after some delay
|
|
debounce(
|
|
debounce(
|
|
combined_name,
|
|
combined_name,
|
|
- () => queueEvents(events, socket),
|
|
|
|
|
|
+ () => queueEvents(_events, socket),
|
|
event_actions.debounce,
|
|
event_actions.debounce,
|
|
);
|
|
);
|
|
} else {
|
|
} else {
|
|
- queueEvents(events, socket);
|
|
|
|
|
|
+ queueEvents(_events, socket);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|