Class SignalBindingUtil
For internal use only. May be renamed or removed in a future release.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SignalBinding<T> effectBinding(Component owner, String bindingType, Signal<T> signal, SerializableConsumer<T> effect) Creates a signal effect withSignal.effect(com.vaadin.flow.component.Component, com.vaadin.flow.signals.function.EffectAction)and returns aSignalBindingthat is notified with the updated signal value when the effect runs.static <T,U> SignalBinding <T> mapBinding(Signal<T> source, SerializableFunction<T, U> mapper, SerializableFunction<Signal<U>, SignalBinding<U>> binder) Maps a signal binding from one type to another.static voidthrowIfBindingActive(Component component, String bindingType) Throws aBindingActiveExceptionif a binding of the specified type is active on the component.
-
Method Details
-
mapBinding
public static <T,U> SignalBinding<T> mapBinding(Signal<T> source, SerializableFunction<T, U> mapper, SerializableFunction<Signal<U>, 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 aSignalBindingtyped 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 typeU- the mapped signal value type used by the underlying binding- Parameters:
source- the source signal with the original type, notnullmapper- function to convert source values to the type expected by the binder, notnullbinder- function that creates a binding from a mapped signal, notnull- Returns:
- a
SignalBindingtyped to the source type
-
effectBinding
public static <T> SignalBinding<T> effectBinding(Component owner, String bindingType, Signal<T> signal, SerializableConsumer<T> effect) Creates a signal effect withSignal.effect(com.vaadin.flow.component.Component, com.vaadin.flow.signals.function.EffectAction)and returns aSignalBindingthat 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
BindingActiveExceptionis thrown. Components can usethrowIfBindingActive(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, notnullbindingType- a unique identifier for the binding type, used to prevent duplicate bindings on the same component, notnullsignal- the signal to observe, notnulleffect- the consumer to invoke with the signal's current value whenever it changes, notnull- Returns:
- a
SignalBindingthat can be used to register change callbacks - Throws:
BindingActiveException- if a binding of the same type is already active on the component
-
throwIfBindingActive
Throws aBindingActiveExceptionif 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, notnullbindingType- a unique identifier for the binding type to check, notnull- Throws:
BindingActiveException- if a binding of the specified type is active on the component
-