فهرست منبع

EventChain.create accepts arbitrary kwargs (#4609)

Pass _var_data when creating LiteralVar

Partial fixes for #4608
Masen Furer 4 ماه پیش
والد
کامیت
fe9c02062d
2فایلهای تغییر یافته به همراه8 افزوده شده و 3 حذف شده
  1. 7 2
      reflex/event.py
  2. 1 1
      reflex/vars/base.py

+ 7 - 2
reflex/event.py

@@ -439,6 +439,7 @@ class EventChain(EventActionsMixin):
         value: EventType,
         value: EventType,
         args_spec: ArgsSpec | Sequence[ArgsSpec],
         args_spec: ArgsSpec | Sequence[ArgsSpec],
         key: Optional[str] = None,
         key: Optional[str] = None,
+        **event_chain_kwargs,
     ) -> Union[EventChain, Var]:
     ) -> Union[EventChain, Var]:
         """Create an event chain from a variety of input types.
         """Create an event chain from a variety of input types.
 
 
@@ -446,6 +447,7 @@ class EventChain(EventActionsMixin):
             value: The value to create the event chain from.
             value: The value to create the event chain from.
             args_spec: The args_spec of the event trigger being bound.
             args_spec: The args_spec of the event trigger being bound.
             key: The key of the event trigger being bound.
             key: The key of the event trigger being bound.
+            **event_chain_kwargs: Additional kwargs to pass to the EventChain constructor.
 
 
         Returns:
         Returns:
             The event chain.
             The event chain.
@@ -464,6 +466,7 @@ class EventChain(EventActionsMixin):
                     value=value.guess_type(),
                     value=value.guess_type(),
                     args_spec=args_spec,
                     args_spec=args_spec,
                     key=key,
                     key=key,
+                    **event_chain_kwargs,
                 )
                 )
             else:
             else:
                 raise ValueError(
                 raise ValueError(
@@ -503,7 +506,9 @@ class EventChain(EventActionsMixin):
             result = call_event_fn(value, args_spec, key=key)
             result = call_event_fn(value, args_spec, key=key)
             if isinstance(result, Var):
             if isinstance(result, Var):
                 # Recursively call this function if the lambda returned an EventChain Var.
                 # Recursively call this function if the lambda returned an EventChain Var.
-                return cls.create(value=result, args_spec=args_spec, key=key)
+                return cls.create(
+                    value=result, args_spec=args_spec, key=key, **event_chain_kwargs
+                )
             events = [*result]
             events = [*result]
 
 
         # Otherwise, raise an error.
         # Otherwise, raise an error.
@@ -520,7 +525,7 @@ class EventChain(EventActionsMixin):
         return cls(
         return cls(
             events=events,
             events=events,
             args_spec=args_spec,
             args_spec=args_spec,
-            event_actions={},
+            **event_chain_kwargs,
         )
         )
 
 
 
 

+ 1 - 1
reflex/vars/base.py

@@ -581,7 +581,7 @@ class Var(Generic[VAR_TYPE]):
 
 
         # Try to pull the imports and hooks from contained values.
         # Try to pull the imports and hooks from contained values.
         if not isinstance(value, str):
         if not isinstance(value, str):
-            return LiteralVar.create(value)
+            return LiteralVar.create(value, _var_data=_var_data)
 
 
         if _var_is_string is False or _var_is_local is True:
         if _var_is_string is False or _var_is_local is True:
             return cls(
             return cls(