Class SignalBindingUtil

java.lang.Object
com.vaadin.flow.component.shared.internal.SignalBindingUtil

public final class SignalBindingUtil extends Object
Internal utility for working with signal bindings in components.

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

  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> com.vaadin.flow.dom.SignalBinding<T>
    effectBinding(com.vaadin.flow.component.Component owner, String bindingType, com.vaadin.flow.signals.Signal<T> signal, com.vaadin.flow.function.SerializableConsumer<T> effect)
    Creates a signal effect with Signal.effect(com.vaadin.flow.component.Component, com.vaadin.flow.signals.function.EffectAction) and returns a SignalBinding that is notified with the updated signal value when the effect runs.
    static <T, U> com.vaadin.flow.dom.SignalBinding<T>
    mapBinding(com.vaadin.flow.signals.Signal<T> source, com.vaadin.flow.function.SerializableFunction<T,U> mapper, com.vaadin.flow.function.SerializableFunction<com.vaadin.flow.signals.Signal<U>,com.vaadin.flow.dom.SignalBinding<U>> binder)
    Maps a signal binding from one type to another.
    static void
    throwIfBindingActive(com.vaadin.flow.component.Component component, String bindingType)
    Throws a BindingActiveException if a binding of the specified type is active on the component.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • mapBinding

      public static <T, U> com.vaadin.flow.dom.SignalBinding<T> mapBinding(com.vaadin.flow.signals.Signal<T> source, com.vaadin.flow.function.SerializableFunction<T,U> mapper, com.vaadin.flow.function.SerializableFunction<com.vaadin.flow.signals.Signal<U>,com.vaadin.flow.dom.SignalBinding<U>> binder)
      Maps a signal binding from one type to another. Creates a computed signal by applying the mapper to the source signal, delegates to the provided binder function, and returns a SignalBinding typed to the original source type.

      This is useful when a component API works with typed values (e.g. enums) but the underlying binding mechanism works with a different type (e.g. strings).

      Type Parameters:
      T - the source signal value type
      U - the mapped signal value type used by the underlying binding
      Parameters:
      source - the source signal with the original type, not null
      mapper - function to convert source values to the type expected by the binder, not null
      binder - function that creates a binding from a mapped signal, not null
      Returns:
      a SignalBinding typed to the source type
    • effectBinding

      public static <T> com.vaadin.flow.dom.SignalBinding<T> effectBinding(com.vaadin.flow.component.Component owner, String bindingType, com.vaadin.flow.signals.Signal<T> signal, com.vaadin.flow.function.SerializableConsumer<T> effect)
      Creates a signal effect with Signal.effect(com.vaadin.flow.component.Component, com.vaadin.flow.signals.function.EffectAction) and returns a SignalBinding that is notified with the updated signal value when the effect runs.

      This is useful for implementing bind APIs in components which only run side-effects (update a class field, run Javascript), but can not use an existing Flow API (such as Element.bindProperty(String, Signal, SerializableConsumer)) to create a binding.

      The binding is registered on the component using the specified binding type. If a binding of the same type is already active, a BindingActiveException is thrown. Components can use throwIfBindingActive(com.vaadin.flow.component.Component, java.lang.String) to manually check for active bindings in their API methods to prevent changes that would interfere with the binding.

      Type Parameters:
      T - the signal value type
      Parameters:
      owner - the component that owns the effect, not null
      bindingType - a unique identifier for the binding type, used to prevent duplicate bindings on the same component, not null
      signal - the signal to observe, not null
      effect - the consumer to invoke with the signal's current value whenever it changes, not null
      Returns:
      a SignalBinding that can be used to register change callbacks
      Throws:
      com.vaadin.flow.signals.BindingActiveException - if a binding of the same type is already active on the component
    • throwIfBindingActive

      public static void throwIfBindingActive(com.vaadin.flow.component.Component component, String bindingType)
      Throws a BindingActiveException if a binding of the specified type is active on the component. This can be used in component APIs to prevent changes that would interfere with an active binding.
      Parameters:
      component - the component to check for active bindings, not null
      bindingType - a unique identifier for the binding type to check, not null
      Throws:
      com.vaadin.flow.signals.BindingActiveException - if a binding of the specified type is active on the component