Class SignalInput<T>

java.lang.Object
com.vaadin.flow.component.trigger.internal.Action.Input<T>
com.vaadin.flow.component.trigger.internal.SignalInput<T>
Type Parameters:
T - the runtime type of the value produced
All Implemented Interfaces:
Serializable

public class SignalInput<T> extends Action.Input<T>
Reads the current value of a server-side Signal at the moment a trigger fires.

When this input is rendered into a trigger's handler — at the Trigger.triggers(Action...) call site — a component-scoped effect is installed once. It mirrors the signal value to a uniquely-named JavaScript property on the owner component's element via Element.executeJs(java.lang.String, java.lang.Object...); every subsequent signal change pushes the new value to the client. The trigger reads that property at fire time, so the value seen reflects whatever the signal held the last time it propagated.

Constructing a SignalInput has no side effects — no effect is installed and no JS is queued until the input is wired into a trigger.

The owner drives the lifecycle: while it is detached the effect is suspended (and the property on the client retains the last pushed value); on re-attach the effect re-emits the current value.


 ValueSignal<String> textSignal = new ValueSignal<>("Hello");
 new ClickTrigger(copyButton).triggers(new WriteToClipboardAction(
         new SignalInput<>(this, textSignal), null));
 textSignal.set("Goodbye");
 // Clicking the button after the set copies "Goodbye".
 

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

See Also:
  • Constructor Details

    • SignalInput

      public SignalInput(Component owner, Signal<T> signal)
      Creates a signal-backed input. No effect is installed until the input is actually rendered into a trigger handler.
      Parameters:
      owner - the component whose lifecycle bounds the signal effect and whose element holds the mirrored value; not null
      signal - the signal whose value should be read at fire time, not null
  • Method Details

    • toJs

      protected JsFunction toJs(Trigger trigger)
      Description copied from class: Action.Input
      Builds the JsFunction that yields this input's value when called. The function may take event as a runtime argument (declared by the subclass via JsFunction.withArguments(String...)); inputs that don't need event simply omit the declaration and ignore the argument the caller passes.
      Specified by:
      toJs in class Action.Input<T>
      Parameters:
      trigger - the surrounding trigger this render is for, not null
      Returns:
      the input's JS function, not null