Class Computation

java.lang.Object
com.vaadin.client.flow.reactive.Computation
All Implemented Interfaces:
ReactiveValueChangeListener

public abstract class Computation extends Object implements 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 Details

    • Computation

      public Computation()
      Creates a new computation.
  • Method Details

    • 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: ReactiveValueChangeListener
      Invoked when a reactive value has changed.
      Specified by:
      onValueChange in interface ReactiveValueChangeListener
      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 time recompute() or Reactive.flush() is invoked.
      Returns:
      true if this computation is invalidated; otherwise false
    • 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