Package com.vaadin.client.flow.reactive
Class Computation
- java.lang.Object
-
- com.vaadin.client.flow.reactive.Computation
-
- All Implemented Interfaces:
ReactiveValueChangeListener
public abstract class Computation extends Object implements ReactiveValueChangeListener
Automatically rerunsdoRecompute()whenever any reactive value used by it changes. The recompute method is invoked by the next invocation ofReactive.flush(), unless it has been invoked manually before the global flush. A computation is also scheduled to for an initial "recomputation" when it is created.- Since:
- 1.0
- Author:
- Vaadin Ltd
-
-
Constructor Summary
Constructors Constructor Description Computation()Creates a new computation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddDependency(ReactiveValue dependency)Adds a dependency to a reactive value.protected abstract voiddoRecompute()Does the actual recomputation.booleanisInvalidated()Checks whether this computation is invalidated.voidonNextInvalidate(InvalidateListener listener)Adds an invalidate listener that will be invoked the next time this computation is invalidated.voidonValueChange(ReactiveValueChangeEvent changeEvent)Invoked when a reactive value has changed.voidrecompute()Recomputes this computation.voidstop()Stops this computation, so that it will no longer be recomputed.
-
-
-
Method Detail
-
addDependency
public void addDependency(ReactiveValue dependency)
Adds a dependency to a reactive value. This computation is scheduled for recomputation when any dependency fires a change event. All previous dependencies are cleared before recomputing.This method is automatically called when a reactive value is used for recomputing this computation. The developer is not expected to call this method himself.
- Parameters:
dependency- the reactive value to depend on
-
onValueChange
public void onValueChange(ReactiveValueChangeEvent changeEvent)
Description copied from interface:ReactiveValueChangeListenerInvoked when a reactive value has changed.- Specified by:
onValueChangein interfaceReactiveValueChangeListener- Parameters:
changeEvent- the change event
-
stop
public void stop()
Stops this computation, so that it will no longer be recomputed.
-
isInvalidated
public boolean isInvalidated()
Checks whether this computation is invalidated. An invalidated computation will eventually be recomputed (unless it has also been stopped). Recomputation will happen the next timerecompute()orReactive.flush()is invoked.- Returns:
trueif this computation is invalidated; otherwisefalse
-
recompute
public void recompute()
Recomputes this computation.
-
doRecompute
protected abstract void doRecompute()
Does the actual recomputation. This method is run in a way that automatically registers dependencies to any reactive value accessed.
-
onNextInvalidate
public void onNextInvalidate(InvalidateListener listener)
Adds an invalidate listener that will be invoked the next time this computation is invalidated.- Parameters:
listener- the listener to run on the next invalidation
-
-