Ver Fonte

fix pyright

Khaleel Al-Adhami há 2 meses atrás
pai
commit
690d029efb
2 ficheiros alterados com 134 adições e 129 exclusões
  1. 18 18
      reflex/.templates/web/utils/state.js
  2. 116 111
      tests/integration/test_event_actions.py

+ 18 - 18
reflex/.templates/web/utils/state.js

@@ -228,8 +228,8 @@ export const applyEvent = async (event, socket) => {
       a.href = eval?.(
         event.payload.url.replace(
           "getBackendURL(env.UPLOAD)",
-          `"${getBackendURL(env.UPLOAD)}"`
-        )
+          `"${getBackendURL(env.UPLOAD)}"`,
+        ),
       );
     }
     a.download = event.payload.filename;
@@ -342,7 +342,7 @@ export const applyRestEvent = async (event, socket) => {
       event.payload.files,
       event.payload.upload_id,
       event.payload.on_upload_progress,
-      socket
+      socket,
     );
     return false;
   }
@@ -419,7 +419,7 @@ export const connect = async (
   dispatch,
   transports,
   setConnectErrors,
-  client_storage = {}
+  client_storage = {},
 ) => {
   // Get backend URL object from the endpoint.
   const endpoint = getBackendURL(EVENTURL);
@@ -509,7 +509,7 @@ export const connect = async (
     for (const substate in update.delta) {
       const new_substate_info = getSubstateFromUpdate(
         update.delta[substate],
-        substate
+        substate,
       );
       if (new_substate_info === null) {
         console.error("Received patch out of order", update.delta[substate]);
@@ -525,7 +525,7 @@ export const connect = async (
     event_processing = !update.final;
     if (failed_substates.length > 0) {
       update.events.push(
-        Event(state_name + ".partial_hydrate", { states: failed_substates })
+        Event(state_name + ".partial_hydrate", { states: failed_substates }),
       );
     }
     if (update.events) {
@@ -556,7 +556,7 @@ export const uploadFiles = async (
   files,
   upload_id,
   on_upload_progress,
-  socket
+  socket,
 ) => {
   // return if there's no file to upload
   if (files === undefined || files.length === 0) {
@@ -661,7 +661,7 @@ export const Event = (
   name,
   payload = {},
   event_actions = {},
-  handler = null
+  handler = null,
 ) => {
   return { name, payload, handler, event_actions };
 };
@@ -688,7 +688,7 @@ export const hydrateClientStorage = (client_storage) => {
     for (const state_key in client_storage.local_storage) {
       const options = client_storage.local_storage[state_key];
       const local_storage_value = localStorage.getItem(
-        options.name || state_key
+        options.name || state_key,
       );
       if (local_storage_value !== null) {
         client_storage_values[state_key] = local_storage_value;
@@ -699,7 +699,7 @@ export const hydrateClientStorage = (client_storage) => {
     for (const state_key in client_storage.session_storage) {
       const session_options = client_storage.session_storage[state_key];
       const session_storage_value = sessionStorage.getItem(
-        session_options.name || state_key
+        session_options.name || state_key,
       );
       if (session_storage_value != null) {
         client_storage_values[state_key] = session_storage_value;
@@ -724,7 +724,7 @@ export const hydrateClientStorage = (client_storage) => {
 const applyClientStorageDelta = (client_storage, delta) => {
   // find the main state and check for is_hydrated
   const unqualified_states = Object.keys(delta).filter(
-    (key) => key.split(".").length === 1
+    (key) => key.split(".").length === 1,
   );
   if (unqualified_states.length === 1) {
     const main_state = delta[unqualified_states[0]];
@@ -758,7 +758,7 @@ const applyClientStorageDelta = (client_storage, delta) => {
         const session_options = client_storage.session_storage[state_key];
         sessionStorage.setItem(
           session_options.name || state_key,
-          delta[substate][key]
+          delta[substate][key],
         );
       }
     }
@@ -778,7 +778,7 @@ const applyClientStorageDelta = (client_storage, delta) => {
 export const useEventLoop = (
   dispatch,
   initial_events = () => [],
-  client_storage = {}
+  client_storage = {},
 ) => {
   const socket = useRef(null);
   const router = useRouter();
@@ -792,7 +792,7 @@ export const useEventLoop = (
 
     event_actions = events.reduce(
       (acc, e) => ({ ...acc, ...e.event_actions }),
-      event_actions ?? {}
+      event_actions ?? {},
     );
 
     const _e = args.filter((o) => o?.preventDefault !== undefined)[0];
@@ -820,7 +820,7 @@ export const useEventLoop = (
       debounce(
         combined_name,
         () => queueEvents(events, socket),
-        event_actions.debounce
+        event_actions.debounce,
       );
     } else {
       queueEvents(events, socket);
@@ -886,7 +886,7 @@ export const useEventLoop = (
           dispatch,
           ["websocket"],
           setConnectErrors,
-          client_storage
+          client_storage,
         );
       }
     }
@@ -935,7 +935,7 @@ export const useEventLoop = (
         vars[storage_to_state_map[e.key]] = e.newValue;
         const event = Event(
           `${state_name}.reflex___state____update_vars_internal_state.update_vars_internal`,
-          { vars: vars }
+          { vars: vars },
         );
         addEvents([event], e);
       }
@@ -1028,7 +1028,7 @@ export const getRefValues = (refs) => {
   return refs.map((ref) =>
     ref.current
       ? ref.current.value || ref.current.getAttribute("aria-valuenow")
-      : null
+      : null,
   );
 };
 

+ 116 - 111
tests/integration/test_event_actions.py

@@ -59,124 +59,129 @@ def TestEventAction():
         def get_event_triggers(self):
             return {"on_click": lambda: []}
 
-    def index():
-        return rx.vstack(
-            rx.input(
-                value=EventActionState.router.session.client_token,
-                is_read_only=True,
-                id="token",
-            ),
-            rx.button("No events", id="btn-no-events"),
-            rx.button(
-                "Stop Prop Only",
-                id="btn-stop-prop-only",
-                on_click=rx.stop_propagation,  # pyright: ignore [reportArgumentType]
-            ),
-            rx.button(
-                "Click event",
-                on_click=EventActionState.on_click("no_event_actions"),  # pyright: ignore [reportCallIssue]
-                id="btn-click-event",
-            ),
-            rx.button(
-                "Click stop propagation",
-                on_click=EventActionState.on_click("stop_propagation").stop_propagation,  # pyright: ignore [reportCallIssue]
-                id="btn-click-stop-propagation",
-            ),
-            rx.button(
-                "Click stop propagation2",
-                on_click=EventActionState.on_click2.stop_propagation,
-                id="btn-click-stop-propagation2",
-            ),
-            rx.button(
-                "Click event 2",
-                on_click=EventActionState.on_click2,
-                id="btn-click-event2",
-            ),
-            rx.link(
-                "Link",
-                href="#",
-                on_click=EventActionState.on_click("link_no_event_actions"),  # pyright: ignore [reportCallIssue]
-                id="link",
-            ),
-            rx.link(
-                "Link Stop Propagation",
-                href="#",
-                on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
-                    "link_stop_propagation"
-                ).stop_propagation,
-                id="link-stop-propagation",
-            ),
-            rx.link(
-                "Link Prevent Default Only",
-                href="/invalid",
-                on_click=rx.prevent_default,  # pyright: ignore [reportArgumentType]
-                id="link-prevent-default-only",
-            ),
-            rx.link(
-                "Link Prevent Default",
-                href="/invalid",
-                on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
-                    "link_prevent_default"
-                ).prevent_default,
-                id="link-prevent-default",
-            ),
-            rx.link(
-                "Link Both",
-                href="/invalid",
-                on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
-                    "link_both"
-                ).stop_propagation.prevent_default,
-                id="link-stop-propagation-prevent-default",
-            ),
-            EventFiringComponent.create(
-                id="custom-stop-propagation",
-                on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
-                    "custom-stop-propagation"
-                ).stop_propagation,
-            ),
-            EventFiringComponent.create(
-                id="custom-prevent-default",
-                on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
-                    "custom-prevent-default"
-                ).prevent_default,
-            ),
-            rx.button(
-                "Throttle",
-                id="btn-throttle",
-                on_click=lambda: EventActionState.on_click_throttle.throttle(  # pyright: ignore [reportFunctionMemberAccess]
-                    200
-                ).stop_propagation,
-            ),
-            rx.button(
-                "Debounce",
-                id="btn-debounce",
-                on_click=EventActionState.on_click_debounce.debounce(  # pyright: ignore [reportFunctionMemberAccess]
-                    200
-                ).stop_propagation,
-            ),
-            rx.list(  # pyright: ignore [reportAttributeAccessIssue]
-                rx.foreach(
-                    EventActionState.order,
-                    rx.list_item,
+    def index() -> rx.Component:
+        return rx.fragment(
+            rx.vstack(
+                rx.input(
+                    value=EventActionState.router.session.client_token,
+                    is_read_only=True,
+                    id="token",
                 ),
-            ),
-            on_click=EventActionState.on_click("outer"),  # pyright: ignore [reportCallIssue]
-        ), rx.form(
-            rx.dialog.root(
-                rx.dialog.trigger(
-                    rx.button("Open Dialog", type="button", id="btn-dialog"),
+                rx.button("No events", id="btn-no-events"),
+                rx.button(
+                    "Stop Prop Only",
+                    id="btn-stop-prop-only",
                     on_click=rx.stop_propagation,  # pyright: ignore [reportArgumentType]
                 ),
-                rx.dialog.content(
-                    rx.dialog.close(
-                        rx.form(
-                            rx.button("Submit", id="btn-submit"),
-                            on_submit=EventActionState.on_submit.stop_propagation,  # pyright: ignore [reportCallIssue]
+                rx.button(
+                    "Click event",
+                    on_click=EventActionState.on_click("no_event_actions"),  # pyright: ignore [reportCallIssue]
+                    id="btn-click-event",
+                ),
+                rx.button(
+                    "Click stop propagation",
+                    on_click=EventActionState.on_click(
+                        "stop_propagation"
+                    ).stop_propagation,  # pyright: ignore [reportCallIssue]
+                    id="btn-click-stop-propagation",
+                ),
+                rx.button(
+                    "Click stop propagation2",
+                    on_click=EventActionState.on_click2.stop_propagation,
+                    id="btn-click-stop-propagation2",
+                ),
+                rx.button(
+                    "Click event 2",
+                    on_click=EventActionState.on_click2,
+                    id="btn-click-event2",
+                ),
+                rx.link(
+                    "Link",
+                    href="#",
+                    on_click=EventActionState.on_click("link_no_event_actions"),  # pyright: ignore [reportCallIssue]
+                    id="link",
+                ),
+                rx.link(
+                    "Link Stop Propagation",
+                    href="#",
+                    on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
+                        "link_stop_propagation"
+                    ).stop_propagation,
+                    id="link-stop-propagation",
+                ),
+                rx.link(
+                    "Link Prevent Default Only",
+                    href="/invalid",
+                    on_click=rx.prevent_default,  # pyright: ignore [reportArgumentType]
+                    id="link-prevent-default-only",
+                ),
+                rx.link(
+                    "Link Prevent Default",
+                    href="/invalid",
+                    on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
+                        "link_prevent_default"
+                    ).prevent_default,
+                    id="link-prevent-default",
+                ),
+                rx.link(
+                    "Link Both",
+                    href="/invalid",
+                    on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
+                        "link_both"
+                    ).stop_propagation.prevent_default,
+                    id="link-stop-propagation-prevent-default",
+                ),
+                EventFiringComponent.create(
+                    id="custom-stop-propagation",
+                    on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
+                        "custom-stop-propagation"
+                    ).stop_propagation,
+                ),
+                EventFiringComponent.create(
+                    id="custom-prevent-default",
+                    on_click=EventActionState.on_click(  # pyright: ignore [reportCallIssue]
+                        "custom-prevent-default"
+                    ).prevent_default,
+                ),
+                rx.button(
+                    "Throttle",
+                    id="btn-throttle",
+                    on_click=lambda: EventActionState.on_click_throttle.throttle(  # pyright: ignore [reportFunctionMemberAccess]
+                        200
+                    ).stop_propagation,
+                ),
+                rx.button(
+                    "Debounce",
+                    id="btn-debounce",
+                    on_click=EventActionState.on_click_debounce.debounce(  # pyright: ignore [reportFunctionMemberAccess]
+                        200
+                    ).stop_propagation,
+                ),
+                rx.list(  # pyright: ignore [reportAttributeAccessIssue]
+                    rx.foreach(
+                        EventActionState.order,
+                        rx.list_item,
+                    ),
+                ),
+                on_click=EventActionState.on_click("outer"),  # pyright: ignore [reportCallIssue]
+            ),
+            rx.form(
+                rx.dialog.root(
+                    rx.dialog.trigger(
+                        rx.button("Open Dialog", type="button", id="btn-dialog"),
+                        on_click=rx.stop_propagation,  # pyright: ignore [reportArgumentType]
+                    ),
+                    rx.dialog.content(
+                        rx.dialog.close(
+                            rx.form(
+                                rx.button("Submit", id="btn-submit"),
+                                on_submit=EventActionState.on_submit.stop_propagation,  # pyright: ignore [reportCallIssue]
+                            ),
                         ),
                     ),
                 ),
+                on_submit=EventActionState.on_submit,  # pyright: ignore [reportCallIssue]
             ),
-            on_submit=EventActionState.on_submit,  # pyright: ignore [reportCallIssue]
         )
 
     app = rx.App()