Package com.vaadin.client.flow.reactive
Class Computation
java.lang.Object
com.vaadin.client.flow.reactive.Computation
- All Implemented Interfaces:
ReactiveValueChangeListener
Automatically reruns
doRecompute() whenever any reactive value used
by it changes. The recompute method is invoked by the next invocation of
Reactive.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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDependency(ReactiveValue dependency) Adds a dependency to a reactive value.protected abstract voidDoes the actual recomputation.booleanChecks 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.voidRecomputes this computation.voidstop()Stops this computation, so that it will no longer be recomputed.
-
Constructor Details
-
Computation
public Computation()Creates a new computation.
-
-
Method Details
-
addDependency
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
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
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
-