Class SignalBinding<T extends @Nullable Object>

java.lang.Object
com.vaadin.flow.dom.SignalBinding<T>
Type Parameters:
T - the type of the bound signal value
All Implemented Interfaces:
Serializable

public class SignalBinding<T extends @Nullable Object> extends Object implements Serializable
Represents an active binding between a signal and an element property (text, attribute, visibility, etc.). Provides the ability to register callbacks that are invoked whenever the binding updates, with rich context about the update.

Typical usage:

 span.bindText(signal).onChange(ctx -> {
     if (ctx.isBackgroundChange()) {
         ctx.getElement().flashClass("highlight");
     }
 });
 
See Also:
  • Method Details

    • getEffectRegistration

      public Registration getEffectRegistration()
      Gets the registration that controls the lifecycle of the underlying effect. Removing the registration stops the effect from running.

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

      Returns:
      the effect registration, or null if not set
    • onChange

      public SignalBinding<T> onChange(SerializableConsumer<BindingContext<T>> action)
      Registers a callback that is invoked every time the bound signal value changes and the binding updates the element. The callback receives a BindingContext that provides the old value, new value, target element, nearest component, and whether the change was a background update, initial render, or user-triggered.

      Multiple callbacks can be registered by calling this method multiple times. All registered callbacks are invoked in registration order.

      Example:

       span.bindText(signal).onChange(ctx -> {
           if (ctx.isBackgroundChange()) {
               ctx.getElement().flashClass("highlight");
           }
       });
       
      Parameters:
      action - the callback to invoke on each update, not null
      Returns:
      this binding for fluent chaining