@@ -0,0 +1,1467 @@
+package org.realityforge.arez.api2;%0A%0Aimport javax.annotation.Nonnull;%0A%0A/**%0A * A derivation that calculates a value and produces an observable value.%0A *%0A * The ComputedValue will remember the result of the computation for the duration%0A * of a batch, or while being observed.%0A *%0A * During this time the ComputedValue will recompute only when one of its direct%0A * dependencies has changed, but only when it is being accessed with %60ComputedValue.get()%60.%0A *%0A * Implementation description:%0A * 1. First time it's being accessed it will compute and remember result%0A *    give back remembered result until 2. happens%0A * 2. First time any deep dependency change, propagate POSSIBLY_STALE to all observers, wait for 3.%0A * 3. When it's being accessed, recompute if any shallow dependency changed.%0A *    if result changed: propagate STALE to all observers, that were POSSIBLY_STALE from the last step.%0A *    go to step 2. either way%0A *%0A * If at any point it's outside batch and it isn't observed: reset everything and go to 1.%0A */%0Apublic final class ComputedValue%0A  extends Derivation%0A  implements Observer%0A%7B%0A  /**%0A   * The value that is computed from derivation.%0A   */%0A  @Nonnull%0A  private final Observable _observable;%0A%0A  public ComputedValue( @Nonnull final ArezContext context, @Nonnull final String name )%0A  %7B%0A    super( context, name );%0A    _observable = new Observable( context, this );%0A  %7D%0A%0A  @Nonnull%0A  public Observable getObservable()%0A  %7B%0A    return _observable;%0A  %7D%0A%7D%0A

Copy across ComputedValue