浏览代码

Add shim for `format_event_chain` (#3958)

Allow `format_event_chain` to continue working until 0.7.0 to allow third party
component wraps to adapt.
Masen Furer 8 月之前
父节点
当前提交
d4cd512144
共有 1 个文件被更改,包括 32 次插入0 次删除
  1. 32 0
      reflex/utils/format.py

+ 32 - 0
reflex/utils/format.py

@@ -10,6 +10,7 @@ from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union
 
 from reflex import constants
 from reflex.utils import exceptions, types
+from reflex.utils.console import deprecate
 
 if TYPE_CHECKING:
     from reflex.components.component import ComponentStyle
@@ -502,6 +503,37 @@ if TYPE_CHECKING:
     from reflex.vars import Var
 
 
+def format_event_chain(
+    event_chain: EventChain | Var[EventChain],
+    event_arg: Var | None = None,
+) -> str:
+    """DEPRECATED: format an event chain as a javascript invocation.
+
+    Use str(rx.Var.create(event_chain)) instead.
+
+    Args:
+        event_chain: The event chain to format.
+        event_arg: this argument is ignored.
+
+    Returns:
+        Compiled javascript code to queue the given event chain on the frontend.
+    """
+    deprecate(
+        feature_name="format_event_chain",
+        reason="Use str(rx.Var.create(event_chain)) instead",
+        deprecation_version="0.6.0",
+        removal_version="0.7.0",
+    )
+
+    from reflex.vars import Var
+    from reflex.vars.function import ArgsFunctionOperation
+
+    result = Var.create(event_chain)
+    if isinstance(result, ArgsFunctionOperation):
+        result = result._return_expr
+    return str(result)
+
+
 def format_queue_events(
     events: (
         EventSpec