Skip to content

Commit

Permalink
fix call_function events sent from backend (#4316)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 authored Nov 6, 2024
1 parent b9d73ed commit 93ae79a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions reflex/.templates/web/utils/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ export const applyEvent = async (event, socket) => {
return false;
}

if (event.name == "_call_function") {
if (
event.name == "_call_function" &&
typeof event.payload.function !== "string"
) {
try {
const eval_result = event.payload.function();
if (event.payload.callback) {
Expand All @@ -257,9 +260,13 @@ export const applyEvent = async (event, socket) => {
return false;
}

if (event.name == "_call_script") {
if (event.name == "_call_script" || event.name == "_call_function") {
try {
const eval_result = eval(event.payload.javascript_code);
const eval_result =
event.name == "_call_script"
? eval(event.payload.javascript_code)
: eval(event.payload.function)();

if (event.payload.callback) {
if (!!eval_result && typeof eval_result.then === "function") {
eval(event.payload.callback)(await eval_result);
Expand Down

0 comments on commit 93ae79a

Please sign in to comment.