Class SinkTrigger

java.lang.Object
com.vaadin.flow.component.trigger.internal.Trigger
com.vaadin.flow.component.trigger.internal.SinkTrigger
All Implemented Interfaces:
Serializable

public class SinkTrigger extends Trigger
A trigger that installs no client-side listener of its own: it hands the rendered action function to a 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 Details

    • SinkTrigger

      public SinkTrigger(Element host, ClientActionSink sink)
      Creates a trigger that hands its rendered actions to sink.
      Parameters:
      host - the element whose lifecycle the trigger belongs to (the renderer's container), not null
      sink - receives the rendered action function, not null
  • Method Details

    • install

      protected Registration install(JsFunction action)
      Description copied from class: Trigger
      Installs the given rendered action as a client-side listener and returns the Registration that detaches it. Called once per action passed to Trigger.triggers(Action...).

      Implementations typically pass getHost().addJsInitializer an initializer that hands the action JsFunction to 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 with this bound 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:
      install in class Trigger
      Parameters:
      action - the rendered action JsFunction; takes the runtime arguments event (the trigger's event payload) and context (what the trigger fired for, or undefined for triggers without one), not null
      Returns:
      the registration whose Registration.remove() detaches the listener, not null