diff --git a/reflex/.templates/web/utils/state.js b/reflex/.templates/web/utils/state.js index 38d33773291..1e11dd9c3f3 100644 --- a/reflex/.templates/web/utils/state.js +++ b/reflex/.templates/web/utils/state.js @@ -415,7 +415,7 @@ export const applyRestEvent = async (event, socket, navigate, params) => { if (event.payload.files === undefined || event.payload.files.length === 0) { // Submit the event over the websocket to trigger the event handler. return await applyEvent( - Event(event.name, { files: [] }), + ReflexEvent(event.name, { files: [] }), socket, navigate, params, @@ -775,7 +775,7 @@ export const uploadFiles = async ( * @param {string} handler The client handler to process event. * @returns The event object. */ -export const Event = ( +export const ReflexEvent = ( name, payload = {}, event_actions = {}, @@ -987,7 +987,7 @@ export const useEventLoop = ( window.onerror = function (msg, url, lineNo, columnNo, error) { addEvents([ - Event(`${exception_state_name}.handle_frontend_exception`, { + ReflexEvent(`${exception_state_name}.handle_frontend_exception`, { info: error.name + ": " + error.message + "\n" + error.stack, component_stack: "", }), @@ -999,7 +999,7 @@ export const useEventLoop = ( //https://github.com/mknichel/javascript-errors?tab=readme-ov-file#promise-rejection-events window.onunhandledrejection = function (event) { addEvents([ - Event(`${exception_state_name}.handle_frontend_exception`, { + ReflexEvent(`${exception_state_name}.handle_frontend_exception`, { info: event.reason?.name + ": " + @@ -1072,7 +1072,7 @@ export const useEventLoop = ( if (storage_to_state_map[e.key]) { const vars = {}; vars[storage_to_state_map[e.key]] = e.newValue; - const event = Event( + const event = ReflexEvent( `${state_name}.reflex___state____update_vars_internal_state.update_vars_internal`, { vars: vars }, ); diff --git a/reflex/compiler/templates.py b/reflex/compiler/templates.py index 3547dd4e955..ba286a8decc 100644 --- a/reflex/compiler/templates.py +++ b/reflex/compiler/templates.py @@ -303,7 +303,7 @@ def context_template( // But only send the vars if any are actually set in the browser. if (client_storage_vars && Object.keys(client_storage_vars).length !== 0) {{ internal_events.push( - Event( + ReflexEvent( '{state_name}.{constants.CompileVars.UPDATE_VARS_INTERNAL}', {{vars: client_storage_vars}}, ), @@ -312,14 +312,14 @@ def context_template( // `on_load_internal` triggers the correct on_load event(s) for the current page. // If the page does not define any on_load event, this will just set `is_hydrated = true`. - internal_events.push(Event('{state_name}.{constants.CompileVars.ON_LOAD_INTERNAL}')); + internal_events.push(ReflexEvent('{state_name}.{constants.CompileVars.ON_LOAD_INTERNAL}')); return internal_events; }} // The following events are sent when the websocket connects or reconnects. export const initialEvents = () => [ - Event('{state_name}.{constants.CompileVars.HYDRATE}'), + ReflexEvent('{state_name}.{constants.CompileVars.HYDRATE}'), ...onLoadInternalEvent() ] """ @@ -351,7 +351,7 @@ def context_template( ) return rf"""import {{ createContext, useContext, useMemo, useReducer, useState, createElement, useEffect }} from "react" -import {{ applyDelta, Event, hydrateClientStorage, useEventLoop, refs }} from "$/utils/state" +import {{ applyDelta, ReflexEvent, hydrateClientStorage, useEventLoop, refs }} from "$/utils/state" import {{ jsx }} from "@emotion/react"; export const initialState = {"{}" if not initial_state else json_dumps(initial_state)} diff --git a/reflex/components/component.py b/reflex/components/component.py index ecee612ec52..5db03404668 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -2599,7 +2599,7 @@ def _get_memoized_event_triggers( memo_name = f"{event_trigger}_{chain_hash}" # Calculate Var dependencies accessed by the handler for useCallback dep array. - var_deps = ["addEvents", "Event"] + var_deps = ["addEvents", "ReflexEvent"] # Get deps from event trigger var data. var_deps.extend(cls._get_deps_from_event_trigger(event)) diff --git a/reflex/constants/compiler.py b/reflex/constants/compiler.py index d063f1a303e..873cce69a14 100644 --- a/reflex/constants/compiler.py +++ b/reflex/constants/compiler.py @@ -64,7 +64,7 @@ class CompileVars(SimpleNamespace): # The name of the var storing any connection error. CONNECT_ERROR = "connectErrors" # The name of the function for converting a dict to an event. - TO_EVENT = "Event" + TO_EVENT = "ReflexEvent" # The name of the internal on_load event. ON_LOAD_INTERNAL = "reflex___state____on_load_internal_state.on_load_internal" # The name of the internal event to update generic state vars. diff --git a/reflex/event.py b/reflex/event.py index faada156c29..d2b37b024f3 100644 --- a/reflex/event.py +++ b/reflex/event.py @@ -1930,7 +1930,7 @@ def no_args(): _var_type=EventSpec, _var_data=_var_data, _var_value=value, - _func=FunctionStringVar("Event"), + _func=FunctionStringVar("ReflexEvent"), _args=( # event handler name ".".join( diff --git a/reflex/utils/format.py b/reflex/utils/format.py index 613fdb93e2f..6d7b87624d8 100644 --- a/reflex/utils/format.py +++ b/reflex/utils/format.py @@ -518,7 +518,7 @@ def format_event(event_spec: EventSpec) -> str: if event_spec.client_handler_name: event_args.append(wrap(event_spec.client_handler_name, '"')) - return f"Event({', '.join(event_args)})" + return f"ReflexEvent({', '.join(event_args)})" if TYPE_CHECKING: diff --git a/tests/units/test_app.py b/tests/units/test_app.py index 0c89c3746e1..699a89722fa 100644 --- a/tests/units/test_app.py +++ b/tests/units/test_app.py @@ -1373,8 +1373,8 @@ def test_app_wrap_compile_theme( "return (" + ("jsx(StrictMode,{}," if react_strict_mode else "") + "jsx(ErrorBoundary,{" - """fallbackRender:((event_args) => (jsx("div", ({css:({ ["height"] : "100%", ["width"] : "100%", ["position"] : "absolute", ["backgroundColor"] : "#fff", ["color"] : "#000", ["display"] : "flex", ["alignItems"] : "center", ["justifyContent"] : "center" })}), (jsx("div", ({css:({ ["display"] : "flex", ["flexDirection"] : "column", ["gap"] : "1rem" })}), (jsx("div", ({css:({ ["display"] : "flex", ["flexDirection"] : "column", ["gap"] : "1rem", ["maxWidth"] : "50ch", ["border"] : "1px solid #888888", ["borderRadius"] : "0.25rem", ["padding"] : "1rem" })}), (jsx("h2", ({css:({ ["fontSize"] : "1.25rem", ["fontWeight"] : "bold" })}), "An error occurred while rendering this page.")), (jsx("p", ({css:({ ["opacity"] : "0.75" })}), "This is an error with the application itself.")), (jsx("details", ({}), (jsx("summary", ({css:({ ["padding"] : "0.5rem" })}), "Error message")), (jsx("div", ({css:({ ["width"] : "100%", ["maxHeight"] : "50vh", ["overflow"] : "auto", ["background"] : "#000", ["color"] : "#fff", ["borderRadius"] : "0.25rem" })}), (jsx("div", ({css:({ ["padding"] : "0.5rem", ["width"] : "fit-content" })}), (jsx("pre", ({}), event_args.error.name + \': \' + event_args.error.message + \'\\n\' + event_args.error.stack)))))), (jsx("button", ({css:({ ["padding"] : "0.35rem 0.75rem", ["margin"] : "0.5rem", ["background"] : "#fff", ["color"] : "#000", ["border"] : "1px solid #000", ["borderRadius"] : "0.25rem", ["fontWeight"] : "bold" }),onClick:((_e) => (addEvents([(Event("_call_function", ({ ["function"] : (() => (navigator["clipboard"]["writeText"](event_args.error.name + \': \' + event_args.error.message + \'\\n\' + event_args.error.stack))), ["callback"] : null }), ({ })))], [_e], ({ }))))}), "Copy")))))), (jsx("hr", ({css:({ ["borderColor"] : "currentColor", ["opacity"] : "0.25" })}))), (jsx(ReactRouterLink, ({to:"https://reflex.dev"}), (jsx("div", ({css:({ ["display"] : "flex", ["alignItems"] : "baseline", ["justifyContent"] : "center", ["fontFamily"] : "monospace", ["--default-font-family"] : "monospace", ["gap"] : "0.5rem" })}), "Built with ", (jsx("svg", ({"aria-label":"Reflex",css:({ ["fill"] : "currentColor" }),height:"12",role:"img",width:"56",xmlns:"http://www.w3.org/2000/svg"}), (jsx("path", ({d:"M0 11.5999V0.399902H8.96V4.8799H6.72V2.6399H2.24V4.8799H6.72V7.1199H2.24V11.5999H0ZM6.72 11.5999V7.1199H8.96V11.5999H6.72Z"}))), (jsx("path", ({d:"M11.2 11.5999V0.399902H17.92V2.6399H13.44V4.8799H17.92V7.1199H13.44V9.3599H17.92V11.5999H11.2Z"}))), (jsx("path", ({d:"M20.16 11.5999V0.399902H26.88V2.6399H22.4V4.8799H26.88V7.1199H22.4V11.5999H20.16Z"}))), (jsx("path", ({d:"M29.12 11.5999V0.399902H31.36V9.3599H35.84V11.5999H29.12Z"}))), (jsx("path", ({d:"M38.08 11.5999V0.399902H44.8V2.6399H40.32V4.8799H44.8V7.1199H40.32V9.3599H44.8V11.5999H38.08Z"}))), (jsx("path", ({d:"M47.04 4.8799V0.399902H49.28V4.8799H47.04ZM53.76 4.8799V0.399902H56V4.8799H53.76ZM49.28 7.1199V4.8799H53.76V7.1199H49.28ZM47.04 11.5999V7.1199H49.28V11.5999H47.04ZM53.76 11.5999V7.1199H56V11.5999H53.76Z"}))), (jsx("title", ({}), "Reflex"))))))))))))),""" - """onError:((_error, _info) => (addEvents([(Event("reflex___state____state.reflex___state____frontend_event_exception_state.handle_frontend_exception", ({ ["info"] : ((((_error["name"]+": ")+_error["message"])+"\\n")+_error["stack"]), ["component_stack"] : _info["componentStack"] }), ({ })))], [_error, _info], ({ }))))""" + """fallbackRender:((event_args) => (jsx("div", ({css:({ ["height"] : "100%", ["width"] : "100%", ["position"] : "absolute", ["backgroundColor"] : "#fff", ["color"] : "#000", ["display"] : "flex", ["alignItems"] : "center", ["justifyContent"] : "center" })}), (jsx("div", ({css:({ ["display"] : "flex", ["flexDirection"] : "column", ["gap"] : "1rem" })}), (jsx("div", ({css:({ ["display"] : "flex", ["flexDirection"] : "column", ["gap"] : "1rem", ["maxWidth"] : "50ch", ["border"] : "1px solid #888888", ["borderRadius"] : "0.25rem", ["padding"] : "1rem" })}), (jsx("h2", ({css:({ ["fontSize"] : "1.25rem", ["fontWeight"] : "bold" })}), "An error occurred while rendering this page.")), (jsx("p", ({css:({ ["opacity"] : "0.75" })}), "This is an error with the application itself.")), (jsx("details", ({}), (jsx("summary", ({css:({ ["padding"] : "0.5rem" })}), "Error message")), (jsx("div", ({css:({ ["width"] : "100%", ["maxHeight"] : "50vh", ["overflow"] : "auto", ["background"] : "#000", ["color"] : "#fff", ["borderRadius"] : "0.25rem" })}), (jsx("div", ({css:({ ["padding"] : "0.5rem", ["width"] : "fit-content" })}), (jsx("pre", ({}), event_args.error.name + \': \' + event_args.error.message + \'\\n\' + event_args.error.stack)))))), (jsx("button", ({css:({ ["padding"] : "0.35rem 0.75rem", ["margin"] : "0.5rem", ["background"] : "#fff", ["color"] : "#000", ["border"] : "1px solid #000", ["borderRadius"] : "0.25rem", ["fontWeight"] : "bold" }),onClick:((_e) => (addEvents([(ReflexEvent("_call_function", ({ ["function"] : (() => (navigator["clipboard"]["writeText"](event_args.error.name + \': \' + event_args.error.message + \'\\n\' + event_args.error.stack))), ["callback"] : null }), ({ })))], [_e], ({ }))))}), "Copy")))))), (jsx("hr", ({css:({ ["borderColor"] : "currentColor", ["opacity"] : "0.25" })}))), (jsx(ReactRouterLink, ({to:"https://reflex.dev"}), (jsx("div", ({css:({ ["display"] : "flex", ["alignItems"] : "baseline", ["justifyContent"] : "center", ["fontFamily"] : "monospace", ["--default-font-family"] : "monospace", ["gap"] : "0.5rem" })}), "Built with ", (jsx("svg", ({"aria-label":"Reflex",css:({ ["fill"] : "currentColor" }),height:"12",role:"img",width:"56",xmlns:"http://www.w3.org/2000/svg"}), (jsx("path", ({d:"M0 11.5999V0.399902H8.96V4.8799H6.72V2.6399H2.24V4.8799H6.72V7.1199H2.24V11.5999H0ZM6.72 11.5999V7.1199H8.96V11.5999H6.72Z"}))), (jsx("path", ({d:"M11.2 11.5999V0.399902H17.92V2.6399H13.44V4.8799H17.92V7.1199H13.44V9.3599H17.92V11.5999H11.2Z"}))), (jsx("path", ({d:"M20.16 11.5999V0.399902H26.88V2.6399H22.4V4.8799H26.88V7.1199H22.4V11.5999H20.16Z"}))), (jsx("path", ({d:"M29.12 11.5999V0.399902H31.36V9.3599H35.84V11.5999H29.12Z"}))), (jsx("path", ({d:"M38.08 11.5999V0.399902H44.8V2.6399H40.32V4.8799H44.8V7.1199H40.32V9.3599H44.8V11.5999H38.08Z"}))), (jsx("path", ({d:"M47.04 4.8799V0.399902H49.28V4.8799H47.04ZM53.76 4.8799V0.399902H56V4.8799H53.76ZM49.28 7.1199V4.8799H53.76V7.1199H49.28ZM47.04 11.5999V7.1199H49.28V11.5999H47.04ZM53.76 11.5999V7.1199H56V11.5999H53.76Z"}))), (jsx("title", ({}), "Reflex"))))))))))))),""" + """onError:((_error, _info) => (addEvents([(ReflexEvent("reflex___state____state.reflex___state____frontend_event_exception_state.handle_frontend_exception", ({ ["info"] : ((((_error["name"]+": ")+_error["message"])+"\\n")+_error["stack"]), ["component_stack"] : _info["componentStack"] }), ({ })))], [_error, _info], ({ }))))""" "}," "jsx(RadixThemesColorModeProvider,{}," "jsx(RadixThemesTheme,{accentColor:\"plum\",css:{...theme.styles.global[':root'], ...theme.styles.global.body}}," @@ -1447,8 +1447,8 @@ def page(): + ("jsx(StrictMode,{}," if react_strict_mode else "") + "jsx(RadixThemesBox,{}," "jsx(ErrorBoundary,{" - """fallbackRender:((event_args) => (jsx("div", ({css:({ ["height"] : "100%", ["width"] : "100%", ["position"] : "absolute", ["backgroundColor"] : "#fff", ["color"] : "#000", ["display"] : "flex", ["alignItems"] : "center", ["justifyContent"] : "center" })}), (jsx("div", ({css:({ ["display"] : "flex", ["flexDirection"] : "column", ["gap"] : "1rem" })}), (jsx("div", ({css:({ ["display"] : "flex", ["flexDirection"] : "column", ["gap"] : "1rem", ["maxWidth"] : "50ch", ["border"] : "1px solid #888888", ["borderRadius"] : "0.25rem", ["padding"] : "1rem" })}), (jsx("h2", ({css:({ ["fontSize"] : "1.25rem", ["fontWeight"] : "bold" })}), "An error occurred while rendering this page.")), (jsx("p", ({css:({ ["opacity"] : "0.75" })}), "This is an error with the application itself.")), (jsx("details", ({}), (jsx("summary", ({css:({ ["padding"] : "0.5rem" })}), "Error message")), (jsx("div", ({css:({ ["width"] : "100%", ["maxHeight"] : "50vh", ["overflow"] : "auto", ["background"] : "#000", ["color"] : "#fff", ["borderRadius"] : "0.25rem" })}), (jsx("div", ({css:({ ["padding"] : "0.5rem", ["width"] : "fit-content" })}), (jsx("pre", ({}), event_args.error.name + \': \' + event_args.error.message + \'\\n\' + event_args.error.stack)))))), (jsx("button", ({css:({ ["padding"] : "0.35rem 0.75rem", ["margin"] : "0.5rem", ["background"] : "#fff", ["color"] : "#000", ["border"] : "1px solid #000", ["borderRadius"] : "0.25rem", ["fontWeight"] : "bold" }),onClick:((_e) => (addEvents([(Event("_call_function", ({ ["function"] : (() => (navigator["clipboard"]["writeText"](event_args.error.name + \': \' + event_args.error.message + \'\\n\' + event_args.error.stack))), ["callback"] : null }), ({ })))], [_e], ({ }))))}), "Copy")))))), (jsx("hr", ({css:({ ["borderColor"] : "currentColor", ["opacity"] : "0.25" })}))), (jsx(ReactRouterLink, ({to:"https://reflex.dev"}), (jsx("div", ({css:({ ["display"] : "flex", ["alignItems"] : "baseline", ["justifyContent"] : "center", ["fontFamily"] : "monospace", ["--default-font-family"] : "monospace", ["gap"] : "0.5rem" })}), "Built with ", (jsx("svg", ({"aria-label":"Reflex",css:({ ["fill"] : "currentColor" }),height:"12",role:"img",width:"56",xmlns:"http://www.w3.org/2000/svg"}), (jsx("path", ({d:"M0 11.5999V0.399902H8.96V4.8799H6.72V2.6399H2.24V4.8799H6.72V7.1199H2.24V11.5999H0ZM6.72 11.5999V7.1199H8.96V11.5999H6.72Z"}))), (jsx("path", ({d:"M11.2 11.5999V0.399902H17.92V2.6399H13.44V4.8799H17.92V7.1199H13.44V9.3599H17.92V11.5999H11.2Z"}))), (jsx("path", ({d:"M20.16 11.5999V0.399902H26.88V2.6399H22.4V4.8799H26.88V7.1199H22.4V11.5999H20.16Z"}))), (jsx("path", ({d:"M29.12 11.5999V0.399902H31.36V9.3599H35.84V11.5999H29.12Z"}))), (jsx("path", ({d:"M38.08 11.5999V0.399902H44.8V2.6399H40.32V4.8799H44.8V7.1199H40.32V9.3599H44.8V11.5999H38.08Z"}))), (jsx("path", ({d:"M47.04 4.8799V0.399902H49.28V4.8799H47.04ZM53.76 4.8799V0.399902H56V4.8799H53.76ZM49.28 7.1199V4.8799H53.76V7.1199H49.28ZM47.04 11.5999V7.1199H49.28V11.5999H47.04ZM53.76 11.5999V7.1199H56V11.5999H53.76Z"}))), (jsx("title", ({}), "Reflex"))))))))))))),""" - """onError:((_error, _info) => (addEvents([(Event("reflex___state____state.reflex___state____frontend_event_exception_state.handle_frontend_exception", ({ ["info"] : ((((_error["name"]+": ")+_error["message"])+"\\n")+_error["stack"]), ["component_stack"] : _info["componentStack"] }), ({ })))], [_error, _info], ({ }))))""" + """fallbackRender:((event_args) => (jsx("div", ({css:({ ["height"] : "100%", ["width"] : "100%", ["position"] : "absolute", ["backgroundColor"] : "#fff", ["color"] : "#000", ["display"] : "flex", ["alignItems"] : "center", ["justifyContent"] : "center" })}), (jsx("div", ({css:({ ["display"] : "flex", ["flexDirection"] : "column", ["gap"] : "1rem" })}), (jsx("div", ({css:({ ["display"] : "flex", ["flexDirection"] : "column", ["gap"] : "1rem", ["maxWidth"] : "50ch", ["border"] : "1px solid #888888", ["borderRadius"] : "0.25rem", ["padding"] : "1rem" })}), (jsx("h2", ({css:({ ["fontSize"] : "1.25rem", ["fontWeight"] : "bold" })}), "An error occurred while rendering this page.")), (jsx("p", ({css:({ ["opacity"] : "0.75" })}), "This is an error with the application itself.")), (jsx("details", ({}), (jsx("summary", ({css:({ ["padding"] : "0.5rem" })}), "Error message")), (jsx("div", ({css:({ ["width"] : "100%", ["maxHeight"] : "50vh", ["overflow"] : "auto", ["background"] : "#000", ["color"] : "#fff", ["borderRadius"] : "0.25rem" })}), (jsx("div", ({css:({ ["padding"] : "0.5rem", ["width"] : "fit-content" })}), (jsx("pre", ({}), event_args.error.name + \': \' + event_args.error.message + \'\\n\' + event_args.error.stack)))))), (jsx("button", ({css:({ ["padding"] : "0.35rem 0.75rem", ["margin"] : "0.5rem", ["background"] : "#fff", ["color"] : "#000", ["border"] : "1px solid #000", ["borderRadius"] : "0.25rem", ["fontWeight"] : "bold" }),onClick:((_e) => (addEvents([(ReflexEvent("_call_function", ({ ["function"] : (() => (navigator["clipboard"]["writeText"](event_args.error.name + \': \' + event_args.error.message + \'\\n\' + event_args.error.stack))), ["callback"] : null }), ({ })))], [_e], ({ }))))}), "Copy")))))), (jsx("hr", ({css:({ ["borderColor"] : "currentColor", ["opacity"] : "0.25" })}))), (jsx(ReactRouterLink, ({to:"https://reflex.dev"}), (jsx("div", ({css:({ ["display"] : "flex", ["alignItems"] : "baseline", ["justifyContent"] : "center", ["fontFamily"] : "monospace", ["--default-font-family"] : "monospace", ["gap"] : "0.5rem" })}), "Built with ", (jsx("svg", ({"aria-label":"Reflex",css:({ ["fill"] : "currentColor" }),height:"12",role:"img",width:"56",xmlns:"http://www.w3.org/2000/svg"}), (jsx("path", ({d:"M0 11.5999V0.399902H8.96V4.8799H6.72V2.6399H2.24V4.8799H6.72V7.1199H2.24V11.5999H0ZM6.72 11.5999V7.1199H8.96V11.5999H6.72Z"}))), (jsx("path", ({d:"M11.2 11.5999V0.399902H17.92V2.6399H13.44V4.8799H17.92V7.1199H13.44V9.3599H17.92V11.5999H11.2Z"}))), (jsx("path", ({d:"M20.16 11.5999V0.399902H26.88V2.6399H22.4V4.8799H26.88V7.1199H22.4V11.5999H20.16Z"}))), (jsx("path", ({d:"M29.12 11.5999V0.399902H31.36V9.3599H35.84V11.5999H29.12Z"}))), (jsx("path", ({d:"M38.08 11.5999V0.399902H44.8V2.6399H40.32V4.8799H44.8V7.1199H40.32V9.3599H44.8V11.5999H38.08Z"}))), (jsx("path", ({d:"M47.04 4.8799V0.399902H49.28V4.8799H47.04ZM53.76 4.8799V0.399902H56V4.8799H53.76ZM49.28 7.1199V4.8799H53.76V7.1199H49.28ZM47.04 11.5999V7.1199H49.28V11.5999H47.04ZM53.76 11.5999V7.1199H56V11.5999H53.76Z"}))), (jsx("title", ({}), "Reflex"))))))))))))),""" + """onError:((_error, _info) => (addEvents([(ReflexEvent("reflex___state____state.reflex___state____frontend_event_exception_state.handle_frontend_exception", ({ ["info"] : ((((_error["name"]+": ")+_error["message"])+"\\n")+_error["stack"]), ["component_stack"] : _info["componentStack"] }), ({ })))], [_error, _info], ({ }))))""" "}," 'jsx(RadixThemesText,{as:"p"},' "jsx(RadixThemesColorModeProvider,{}," diff --git a/tests/units/test_event.py b/tests/units/test_event.py index 7731e49e18b..c7c95709afa 100644 --- a/tests/units/test_event.py +++ b/tests/units/test_event.py @@ -57,7 +57,7 @@ def fn_with_args(_, arg1, arg2): assert event_spec.handler == handler assert event_spec.args == () - assert format.format_event(event_spec) == 'Event("test_fn", {})' + assert format.format_event(event_spec) == 'ReflexEvent("test_fn", {})' handler = EventHandler(fn=fn_with_args) event_spec = handler(make_var("first"), make_var("second")) @@ -70,14 +70,14 @@ def fn_with_args(_, arg1, arg2): assert event_spec.args[1][1].equals(Var(_js_expr="second")) assert ( format.format_event(event_spec) - == 'Event("fn_with_args", {arg1:first,arg2:second})' + == 'ReflexEvent("fn_with_args", {arg1:first,arg2:second})' ) # Passing args as strings should format differently. event_spec = handler("first", "second") assert ( format.format_event(event_spec) - == 'Event("fn_with_args", {arg1:"first",arg2:"second"})' + == 'ReflexEvent("fn_with_args", {arg1:"first",arg2:"second"})' ) first, second = 123, "456" @@ -85,7 +85,7 @@ def fn_with_args(_, arg1, arg2): event_spec = handler(first, second) assert ( format.format_event(event_spec) - == 'Event("fn_with_args", {arg1:123,arg2:"456"})' + == 'ReflexEvent("fn_with_args", {arg1:123,arg2:"456"})' ) assert event_spec.handler == handler @@ -120,7 +120,7 @@ def spec(a2: Var[str]) -> list[Var[str]]: assert event_spec.args[0][1].equals(Var(_js_expr="first")) assert ( format.format_event(event_spec) - == 'Event("BigState.fn_with_args", {arg1:first})' + == 'ReflexEvent("BigState.fn_with_args", {arg1:first})' ) assert event_spec2 is not event_spec @@ -132,7 +132,7 @@ def spec(a2: Var[str]) -> list[Var[str]]: assert event_spec2.args[1][1].equals(Var(_js_expr="_a2", _var_type=str)) assert ( format.format_event(event_spec2) - == 'Event("BigState.fn_with_args", {arg1:first,arg2:_a2})' + == 'ReflexEvent("BigState.fn_with_args", {arg1:first,arg2:_a2})' ) @@ -170,27 +170,27 @@ def fn_with_args(_, arg1, arg2): [ ( ("/path", None, None), - 'Event("_redirect", {path:"/path",external:false,replace:false})', + 'ReflexEvent("_redirect", {path:"/path",external:false,replace:false})', ), ( ("/path", True, None), - 'Event("_redirect", {path:"/path",external:true,replace:false})', + 'ReflexEvent("_redirect", {path:"/path",external:true,replace:false})', ), ( ("/path", False, None), - 'Event("_redirect", {path:"/path",external:false,replace:false})', + 'ReflexEvent("_redirect", {path:"/path",external:false,replace:false})', ), ( (Var(_js_expr="path"), None, None), - 'Event("_redirect", {path:path,external:false,replace:false})', + 'ReflexEvent("_redirect", {path:path,external:false,replace:false})', ), ( ("/path", None, True), - 'Event("_redirect", {path:"/path",external:false,replace:true})', + 'ReflexEvent("_redirect", {path:"/path",external:false,replace:true})', ), ( ("/path", True, True), - 'Event("_redirect", {path:"/path",external:true,replace:true})', + 'ReflexEvent("_redirect", {path:"/path",external:true,replace:true})', ), ], ) @@ -224,17 +224,17 @@ def test_event_console_log(): ) assert ( format.format_event(spec) - == 'Event("_call_function", {function:(() => (console["log"]("message"))),callback:null})' + == 'ReflexEvent("_call_function", {function:(() => (console["log"]("message"))),callback:null})' ) spec = event.console_log(Var(_js_expr="message")) assert ( format.format_event(spec) - == 'Event("_call_function", {function:(() => (console["log"](message))),callback:null})' + == 'ReflexEvent("_call_function", {function:(() => (console["log"](message))),callback:null})' ) spec2 = event.console_log(Var(_js_expr="message2")).add_args(Var("throwaway")) assert ( format.format_event(spec2) - == 'Event("_call_function", {function:(() => (console["log"](message2))),callback:null})' + == 'ReflexEvent("_call_function", {function:(() => (console["log"](message2))),callback:null})' ) @@ -249,17 +249,17 @@ def test_event_window_alert(): ) assert ( format.format_event(spec) - == 'Event("_call_function", {function:(() => (window["alert"]("message"))),callback:null})' + == 'ReflexEvent("_call_function", {function:(() => (window["alert"]("message"))),callback:null})' ) spec = event.window_alert(Var(_js_expr="message")) assert ( format.format_event(spec) - == 'Event("_call_function", {function:(() => (window["alert"](message))),callback:null})' + == 'ReflexEvent("_call_function", {function:(() => (window["alert"](message))),callback:null})' ) spec2 = event.window_alert(Var(_js_expr="message2")).add_args(Var("throwaway")) assert ( format.format_event(spec2) - == 'Event("_call_function", {function:(() => (window["alert"](message2))),callback:null})' + == 'ReflexEvent("_call_function", {function:(() => (window["alert"](message2))),callback:null})' ) @@ -278,9 +278,13 @@ def test_focus(func: str, qualname: str): assert spec.handler.fn.__qualname__ == qualname assert spec.args[0][0].equals(Var(_js_expr="ref")) assert spec.args[0][1].equals(LiteralVar.create("ref_input1")) - assert format.format_event(spec) == f'Event("{qualname}", {{ref:"ref_input1"}})' + assert ( + format.format_event(spec) == f'ReflexEvent("{qualname}", {{ref:"ref_input1"}})' + ) spec = getattr(event, func)("input1") - assert format.format_event(spec) == f'Event("{qualname}", {{ref:"ref_input1"}})' + assert ( + format.format_event(spec) == f'ReflexEvent("{qualname}", {{ref:"ref_input1"}})' + ) def test_set_value(): @@ -293,12 +297,13 @@ def test_set_value(): assert spec.args[1][0].equals(Var(_js_expr="value")) assert spec.args[1][1].equals(LiteralVar.create("")) assert ( - format.format_event(spec) == 'Event("_set_value", {ref:"ref_input1",value:""})' + format.format_event(spec) + == 'ReflexEvent("_set_value", {ref:"ref_input1",value:""})' ) spec = event.set_value("input1", Var(_js_expr="message")) assert ( format.format_event(spec) - == 'Event("_set_value", {ref:"ref_input1",value:message})' + == 'ReflexEvent("_set_value", {ref:"ref_input1",value:message})' ) @@ -313,7 +318,7 @@ def test_remove_cookie(): assert spec.args[1][1].equals(LiteralVar.create({"path": "/"})) assert ( format.format_event(spec) - == 'Event("_remove_cookie", {key:"testkey",options:({ ["path"] : "/" })})' + == 'ReflexEvent("_remove_cookie", {key:"testkey",options:({ ["path"] : "/" })})' ) @@ -334,7 +339,7 @@ def test_remove_cookie_with_options(): assert spec.args[1][1].equals(LiteralVar.create(options)) assert ( format.format_event(spec) - == f'Event("_remove_cookie", {{key:"testkey",options:{LiteralVar.create(options)!s}}})' + == f'ReflexEvent("_remove_cookie", {{key:"testkey",options:{LiteralVar.create(options)!s}}})' ) @@ -344,7 +349,7 @@ def test_clear_local_storage(): assert isinstance(spec, EventSpec) assert spec.handler.fn.__qualname__ == "_clear_local_storage" assert not spec.args - assert format.format_event(spec) == 'Event("_clear_local_storage", {})' + assert format.format_event(spec) == 'ReflexEvent("_clear_local_storage", {})' def test_remove_local_storage(): @@ -355,7 +360,8 @@ def test_remove_local_storage(): assert spec.args[0][0].equals(Var(_js_expr="key")) assert spec.args[0][1].equals(LiteralVar.create("testkey")) assert ( - format.format_event(spec) == 'Event("_remove_local_storage", {key:"testkey"})' + format.format_event(spec) + == 'ReflexEvent("_remove_local_storage", {key:"testkey"})' ) diff --git a/tests/units/utils/test_format.py b/tests/units/utils/test_format.py index e377420449d..8ac6b1fa929 100644 --- a/tests/units/utils/test_format.py +++ b/tests/units/utils/test_format.py @@ -374,7 +374,7 @@ def test_format_match( events=[EventSpec(handler=EventHandler(fn=mock_event))], args_spec=no_args_event_spec, ), - '((...args) => (addEvents([(Event("mock_event", ({ }), ({ })))], args, ({ }))))', + '((...args) => (addEvents([(ReflexEvent("mock_event", ({ }), ({ })))], args, ({ }))))', ), ( EventChain( @@ -395,7 +395,7 @@ def test_format_match( ], args_spec=lambda e: [e.target.value], ), - '((_e) => (addEvents([(Event("mock_event", ({ ["arg"] : _e["target"]["value"] }), ({ })))], [_e], ({ }))))', + '((_e) => (addEvents([(ReflexEvent("mock_event", ({ ["arg"] : _e["target"]["value"] }), ({ })))], [_e], ({ }))))', ), ( EventChain( @@ -403,7 +403,7 @@ def test_format_match( args_spec=no_args_event_spec, event_actions={"stopPropagation": True}, ), - '((...args) => (addEvents([(Event("mock_event", ({ }), ({ })))], args, ({ ["stopPropagation"] : true }))))', + '((...args) => (addEvents([(ReflexEvent("mock_event", ({ }), ({ })))], args, ({ ["stopPropagation"] : true }))))', ), ( EventChain( @@ -415,7 +415,7 @@ def test_format_match( ], args_spec=no_args_event_spec, ), - '((...args) => (addEvents([(Event("mock_event", ({ }), ({ ["stopPropagation"] : true })))], args, ({ }))))', + '((...args) => (addEvents([(ReflexEvent("mock_event", ({ }), ({ ["stopPropagation"] : true })))], args, ({ }))))', ), ( EventChain( @@ -423,7 +423,7 @@ def test_format_match( args_spec=no_args_event_spec, event_actions={"preventDefault": True}, ), - '((...args) => (addEvents([(Event("mock_event", ({ }), ({ })))], args, ({ ["preventDefault"] : true }))))', + '((...args) => (addEvents([(ReflexEvent("mock_event", ({ }), ({ })))], args, ({ ["preventDefault"] : true }))))', ), ({"a": "red", "b": "blue"}, '({ ["a"] : "red", ["b"] : "blue" })'), (Var(_js_expr="var", _var_type=int).guess_type(), "var"), @@ -531,7 +531,7 @@ def test_format_event_handler(input, output): [ ( EventSpec(handler=EventHandler(fn=mock_event)), - '(Event("mock_event", ({ }), ({ })))', + '(ReflexEvent("mock_event", ({ }), ({ })))', ), ], )