Class Trigger
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DomEventTrigger
BroadcastChannel message, a media-query match, … — and, when it does,
runs one or more actions.
Actions run synchronously inside the browser's handler when the trigger
fires; for triggers that originate from a user gesture (click, keypress, …)
this preserves the gesture context for downstream actions, letting them
invoke browser APIs that require it (clipboard, fullscreen, file picker,
share, …). Note that most such APIs are themselves asynchronous: the action
is dispatched synchronously, but any server-observable effect — for example,
a callback reporting whether navigator.clipboard.writeText resolved —
may reach the server arbitrarily later than the gesture itself, after one or
more event-loop turns.
Each Action passed to triggers(Action...) produces one
addJsInitializer registration on the host
element via install(JsFunction) — so a call with N actions yields N
registrations, all detached by remove(). Subclasses implement
install to wire the rendered JsFunction to whatever client
API the trigger wraps (typically passing it to addJsInitializer
alongside whatever literal values the install expression needs).
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal ElementgetHost()The host element this trigger fires on.protected abstract Registrationinstall(JsFunction action) Installs the given rendered action as a client-side listener and returns theRegistrationthat detaches it.final voidremove()Removes this trigger and all wirings created from it.final voidWires the given actions to this trigger.
-
Constructor Details
-
Trigger
Creates a new trigger bound to the given host component's root element.- Parameters:
host- the component whose root element the trigger fires on, notnull
-
-
Method Details
-
getHost
The host element this trigger fires on.- Returns:
- the host element, never
null
-
triggers
Wires the given actions to this trigger. They run in the order given the next time this trigger fires. Each call adds another wiring; the existing ones are kept.- Parameters:
actions- the actions to run, notnullor empty
-
install
Installs the given rendered action as a client-side listener and returns theRegistrationthat detaches it. Called once per action passed totriggers(Action...).Implementations typically call
getHost().addJsInitializerwith an install expression that hands the actionJsFunctionto whatever client API the trigger wraps:
The expression runs withreturn getHost().addJsInitializer( "this.addEventListener($1, $0);" + "return () => this.removeEventListener($1, $0);", action, eventName);thisbound to the host element. The captures are made available as$0,$1, … in the order passed.- Parameters:
action- the rendered actionJsFunction; takes one runtime argument namedevent(the trigger's event payload), notnull- Returns:
- the registration whose
Registration.remove()detaches the listener, notnull
-
remove
public final void remove()Removes this trigger and all wirings created from it. The corresponding client-side listeners are detached as part of the next synchronisation.
-