From d4cd5121447dbf7936f24cc7cfdf5059e0a2b84c Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 19 Sep 2024 19:08:00 -0700 Subject: [PATCH] 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. --- reflex/utils/format.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/reflex/utils/format.py b/reflex/utils/format.py index c804b2946..86b4d96c9 100644 --- a/reflex/utils/format.py +++ b/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