Allow setting a different invocation function for EventChain

In rx.call_script scenario, the EventChain must call `queueEvents` and
`processEvent` instead of `addEvents`, because the former are in scope in the
call_script eval environment where `addEvents` is not.

This is an escape hatch for certain wrapping scenarios.
This commit is contained in:
Masen Furer 2024-10-11 13:25:49 -07:00
parent 210c1ed902
commit 120c8688a3
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95

View File

@ -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
@ -1323,10 +1325,15 @@ class LiteralEventChainVar(CachedVarOperation, LiteralVar, EventChainVar):
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]
),