Class EffectContext

java.lang.Object
com.vaadin.flow.signals.EffectContext
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BindingContext

public class EffectContext extends Object implements Serializable
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 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:
      true if this is the first execution, false otherwise
    • 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 using UI.access(), from server push, or from another user modifying a shared signal.

      This is false during the initial run (even if there is no active request) and false during a normal user request. It is true only 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:
      true if triggered by a background change, false otherwise