Package com.vaadin.flow.dom
Class ElementEffect
java.lang.Object
com.vaadin.flow.dom.ElementEffect
The utility class that provides helper methods for using Signal effects in a
context of a given element's life-cycle.
It ultimately creates a Signal effect, i.e. a call to
Signal.effect(EffectAction), that is automatically enabled when an
element is attached and disabled when the element is detached. Additionally,
it provides methods to bind signals to element according to a given value
setting function.
- Since:
- 25.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Registrationbind(Element owner, com.vaadin.signals.Signal<T> signal, SerializableBiConsumer<Element, T> setter) Binds asignal's value to a given owner element in a way defined insetterfunction and creates a Signal effect function executing the setter whenever the signal value changes.voidclose()static RegistrationCreates a Signal effect that is owned by a given element.
-
Constructor Details
-
ElementEffect
-
-
Method Details
-
effect
Creates a Signal effect that is owned by a given element. The effect is enabled when the element is attached and automatically disabled when it is detached.Example of usage:
Registration effect = ElementEffect.effect(myElement, () -> { Notification.show("Element is attached and signal value is " + someSignal.value()); }); effect.remove(); // to remove the effect when no longer needed- Parameters:
owner- the owner element for which the effect is applied, must not benulleffectFunction- the effect function to be executed when any dependency is changed, must not benull- Returns:
- a
Registrationthat can be used to remove the effect function - See Also:
-
bind
public static <T> Registration bind(Element owner, com.vaadin.signals.Signal<T> signal, SerializableBiConsumer<Element, T> setter) Binds asignal's value to a given owner element in a way defined insetterfunction and creates a Signal effect function executing the setter whenever the signal value changes.Example of usage:
Element mySpan = new Element("span"); Registration effect = ElementEffect.bind(mySpan, stringSignal, Element::setText); effect.remove(); // to remove the effect when no longer needed ElementEffect.bind(mySpan, stringSignal.map(value -> !value.isEmpty()), Element::setVisible);- Type Parameters:
T- the type of the signal value- Parameters:
owner- the owner element for which the effect is applied, must not benullsignal- the signal whose value is to be bound to the element, must not benullsetter- the setter function that defines how the signal value is applied to the element, must not benull- Returns:
- a
Registrationthat can be used to remove the effect function - See Also:
-
close
public void close()
-