Class TimeoutTrigger

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

public class TimeoutTrigger extends Trigger
Fires once, on the client, after the given delay has elapsed. The delay is measured by the browser via a single setTimeout armed when the host is initialized on the client; when it elapses the bound actions run. Pair it with a value-less CallbackAction (or any other action) to run server-side work a short while later without enabling push.

Unlike event- or observer-based triggers, this one fires a single time. The timer is cleared if the trigger is removed before it elapses; because it lives in the browser, it also never fires if the host's client DOM goes away (page reload, navigation, ?) first.

For internal use only. May be renamed or removed in a future release.

Since:
25.2
See Also:
  • Constructor Details

    • TimeoutTrigger

      public TimeoutTrigger(Component host, Duration delay)
      Creates a trigger that fires once, the given delay after the host is initialized on the client.
      Parameters:
      host - the component whose client-side initialization arms the timer, not null
      delay - how long to wait before firing, not null and not negative
  • 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 call getHost().addJsInitializer with an install expression that hands the action JsFunction to whatever client API the trigger wraps:

      
       return getHost().addJsInitializer(
               "this.addEventListener($1, $0);"
                       + "return () => this.removeEventListener($1, $0);",
               action, eventName);
       
      The expression runs with this bound to the host element. The captures are made available as $0, $1, ? in the order passed.
      Specified by:
      install in class Trigger
      Parameters:
      action - the rendered action JsFunction; takes one runtime argument named event (the trigger's event payload), not null
      Returns:
      the registration whose Registration.remove() detaches the listener, not null