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 the effect owner's requests, and updates triggered by background
changes (such as a background thread or another user modifying a shared
signal).
Typical usage:
Signal.effect(this, ctx -> {
span.getElement().setText("$" + price.get());
if (ctx.isBackgroundChange()) {
span.getElement().flashClass("highlight");
}
});
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionEffectContext(boolean initialRun, boolean backgroundChange) Creates a new effect context. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether this execution was triggered by a signal change that happened outside the effect owner's request context.booleanReturns whether this is the very first execution of the effect.
-
Constructor Details
-
EffectContext
public EffectContext(boolean initialRun, boolean backgroundChange) Creates a new effect context.- Parameters:
initialRun- whether this is the first execution of the effectbackgroundChange- whether the invalidation that triggered this execution happened outside a user request context
-
-
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 signal change that happened outside the effect owner's request context. A background change occurs when a signal is modified from a background thread or by another user modifying a shared signal.This is
falseduring the initial run (even if there is no active request) andfalsewhen the signal was changed during a request from the user who owns the effect. It istruewhen the signal change originated from outside any request context for this user.Note: This flag is a hint and may not be fully accurate when multiple signal changes from different sources are batched into a single effect invocation. The flag is guaranteed to not be set if none of the changes are from a background context and guaranteed to be set if all changes are from a background context. When changes come from mixed sources, the state of the flag is arbitrary.
- Returns:
trueif triggered by a background change,falseotherwise
-