Class SinkTrigger
- All Implemented Interfaces:
Serializable
ClientActionSink and lets the sink
decide when it runs.
Used where the thing that fires is rendered on the client and has no
server-side component to listen on — a LitRenderer template binding
@click=${() => copy(item.email)}, for example. The sink passes the
function into the renderer, the template calls it from its own event binding,
and the action therefore runs inside the browser's event handler with the
user gesture still valid, exactly as it does for a DomEventTrigger.
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSinkTrigger(Element host, ClientActionSink sink) Creates a trigger that hands its rendered actions tosink. -
Method Summary
Modifier and TypeMethodDescriptionprotected Registrationinstall(JsFunction action) Installs the given rendered action as a client-side listener and returns theRegistrationthat detaches it.
-
Constructor Details
-
SinkTrigger
Creates a trigger that hands its rendered actions tosink.- Parameters:
host- the element whose lifecycle the trigger belongs to (the renderer's container), notnullsink- receives the rendered action function, notnull
-
-
Method Details
-
install
Description copied from class:TriggerInstalls the given rendered action as a client-side listener and returns theRegistrationthat detaches it. Called once per action passed toTrigger.triggers(Action...).Implementations typically pass
getHost().addJsInitializeran initializer that hands the actionJsFunctionto whatever client API the trigger wraps. The initializer is declared as a snippet, so that nothing is compiled from a string in the browser:@JsExpression("this.addEventListener($1, $0);" + "return () => this.removeEventListener($1, $0);") JsFunction listenToEvent(JsFunction action, String eventName); // In install, with LISTEN_JS = JsSnippets.of(ListenJs.class) return getHost().addJsInitializer( LISTEN_JS.listenToEvent(action, eventName));The initializer runs withthisbound to the host element, and returns the function that uninstalls it. The arguments of the snippet are made available as$0,$1, … in the order passed.- Specified by:
installin classTrigger- Parameters:
action- the rendered actionJsFunction; takes the runtime argumentsevent(the trigger's event payload) andcontext(what the trigger fired for, orundefinedfor triggers without one), notnull- Returns:
- the registration whose
Registration.remove()detaches the listener, notnull
-