Package com.vaadin.flow.signals
Class EffectContext
java.lang.Object
com.vaadin.flow.signals.EffectContext
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
BindingContext
Provides context information about why a signal effect is running. This
allows effect callbacks to distinguish between the initial execution, updates
triggered by user requests, and updates triggered by background changes (such
as server push or other users modifying shared signals).
Typical usage:
Signal.effect(this, ctx -> {
span.getElement().setText("$" + price.get());
if (ctx.isBackgroundChange()) {
span.getElement().flashClass("highlight");
}
});
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether this execution was triggered by a background change rather than by a user request or the initial render.booleanReturns whether this is the very first execution of the effect.
-
Constructor Details
-
EffectContext
public EffectContext(boolean initialRun) Creates a new effect context.- Parameters:
initialRun- whether this is the first execution of the effect
-
-
Method Details
-
isInitialRun
public boolean isInitialRun()Returns whether this is the very first execution of the effect. The initial run happens when the effect is first created (or when a bound component is first attached).- Returns:
trueif this is the first execution,falseotherwise
-
isBackgroundChange
public boolean isBackgroundChange()Returns whether this execution was triggered by a background change rather than by a user request or the initial render. A background change occurs when a signal is modified outside of a user request context, for example from a background thread usingUI.access(), from server push, or from another user modifying a shared signal.This is
falseduring the initial run (even if there is no active request) andfalseduring a normal user request. It istrueonly when the effect re-runs due to a signal change that happened outside any user request.Note: async user actions (user click leading to async work, then
ui.access(() -> signal.set(...))) are classified as background changes because by the time the async result arrives, there is no active request.- Returns:
trueif triggered by a background change,falseotherwise
-