Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a different invocation function for EventChain #4160

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion reflex/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ class EventChain(EventActionsMixin):

args_spec: Optional[Callable] = dataclasses.field(default=None)

invocation: Optional[Var] = dataclasses.field(default=None)


# These chains can be used for their side effects when no other events are desired.
stop_propagation = EventChain(events=[], args_spec=lambda: []).stop_propagation
Expand Down Expand Up @@ -1323,10 +1325,15 @@ def _cached_var_name(self) -> str:
arg_def = ("...args",)
arg_def_expr = Var(_js_expr="args")

if self._var_value.invocation is None:
invocation = FunctionStringVar.create("addEvents")
else:
invocation = self._var_value.invocation

return str(
ArgsFunctionOperation.create(
arg_def,
FunctionStringVar.create("addEvents").call(
invocation.call(
LiteralVar.create(
[LiteralVar.create(event) for event in self._var_value.events]
),
Expand Down
Loading