Package com.vaadin.flow.signals.impl
Class Effect
java.lang.Object
com.vaadin.flow.signals.impl.Effect
- All Implemented Interfaces:
Serializable
Applies a side effect based on signal value changes. An effect is a callback
that is initially run when the effect is created, and subsequently run again
whenever any dependency changes. Dependencies are automatically registered
for all signals that are read from the callback. The callback is run again
whenever there's a change to any dependency. Dependencies are always updated
based the signals read during the most recent invocation.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionEffect(ContextualEffectAction action) Creates a context-aware signal effect with the given action and the default dispatcher.Effect(ContextualEffectAction action, SerializableExecutor dispatcher) Creates a context-aware signal effect with the given action and a custom dispatcher.Effect(EffectAction action) Creates a signal effect with the given action and the default dispatcher.Effect(EffectAction action, SerializableExecutor dispatcher) Creates a signal effect with the given action and a custom dispatcher. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Re-activates a previously passivated effect.voiddispose()Disposes this effect by unregistering all current dependencies and preventing the action from running again.voidPassivates this effect by removing all dependency listeners while preserving the tracked usages.voidsetDispatcher(SerializableExecutor dispatcher) Sets the dispatcher to use for subsequent invalidation callbacks.voidsetOwnerUI(@Nullable UI ui) Sets the owner UI for this effect.
-
Constructor Details
-
Effect
Creates a signal effect with the given action and the default dispatcher. The action is run when the effect is created and is subsequently run again whenever there's a change to any signal value that was read during the last invocation.- Parameters:
action- the action to use, notnull- See Also:
-
Effect
Creates a signal effect with the given action and a custom dispatcher. The action is run when the effect is created and is subsequently run again whenever there's a change to any signal value that was read during the last invocation. The dispatcher can be used to make sure changes are evaluated asynchronously or with some specific context available. The action itself needs to be synchronous to be able to track changes.- Parameters:
action- the action to use, notnulldispatcher- the dispatcher to use when handling changes, notnull
-
Effect
Creates a context-aware signal effect with the given action and the default dispatcher. The action receives anEffectContextthat provides information about why the effect is running (initial render, user request, or background change).- Parameters:
action- the context-aware action to use, notnull- See Also:
-
Effect
Creates a context-aware signal effect with the given action and a custom dispatcher. The action receives anEffectContextthat provides information about why the effect is running. The dispatcher can be used to make sure changes are evaluated asynchronously or with some specific context available. The action itself needs to be synchronous to be able to track changes.- Parameters:
action- the context-aware action to use, notnulldispatcher- the dispatcher to use when handling changes, notnull
-
-
Method Details
-
setOwnerUI
Sets the owner UI for this effect. When set, background change detection comparesUI.getCurrent()against this UI instead of only checking for the presence of aVaadinRequest. This allows effects to correctly detect changes triggered by another user's session on a shared signal.- Parameters:
ui- the owner UI, ornullto fall back to VaadinRequest-based detection
-
setDispatcher
Sets the dispatcher to use for subsequent invalidation callbacks. This can be used to change the execution context before re-activating a passivated effect.- Parameters:
dispatcher- the new dispatcher to use, notnull
-
passivate
public void passivate()Passivates this effect by removing all dependency listeners while preserving the tracked usages. The effect can later be re-activated withactivate(), which will check if any tracked values have changed and only re-run the callback if needed. -
activate
public void activate()Re-activates a previously passivated effect. If any tracked signal has changed since passivation, the effect callback is re-run withEffectContext.isInitialRun()returningtrue. If nothing has changed, the effect simply re-registers its dependency listeners without running the callback. -
dispose
public void dispose()Disposes this effect by unregistering all current dependencies and preventing the action from running again.
-