package arez.doc.examples.step5;

import arez.annotations.Action;
import arez.annotations.ArezComponent;
import arez.annotations.Memoize;
import arez.annotations.Executor;
import arez.annotations.Feature;
import arez.annotations.Observable;
import arez.annotations.Observe;
import arez.annotations.OnDepsChange;

@ArezComponent
public abstract class TrainTicket
{
  public static TrainTicket create( int remainingRides )
  {
    return new Arez_TrainTicket( remainingRides );
  }

  @Observable( initializer = Feature.ENABLE )
  public abstract int getRemainingRides();

  public abstract void setRemainingRides( int remainingRides );

  @Action
  public void rideTrain()
  {
    setRemainingRides( getRemainingRides() - 1 );
  }

  @Observe( executor = Executor.EXTERNAL )
  public String render()
  {
    return "<table class='ticket'>" +
           "  <tr>" +
           "    <th>Remaining Rides</th>" +
           "    <td>" + getRemainingRides() + "</td>" +
           "  </tr>" +
           "</table>";
  }

  @OnDepsChange
  void onRenderDepsChange()
  {
    Renderer.scheduleRender( this );
  }

  @Memoize
  public boolean isTicketExpired()
  {
    return 0 == getRemainingRides();
  }

  @Observe
  void notifyUserWhenTicketExpires()
  {
    if ( isTicketExpired() )
    {
      NotifyTool.notifyUserTicketExpired( this );
    }
  }
}

@@ -102,41 +102,8 @@
 nt;%0A
-import arez.annotations.Memoize;%0A
 impo
@@ -189,25 +189,22 @@
 tations.
-Observabl
+Memoiz
 e;%0Aimpor
@@ -228,16 +228,19 @@
 s.Observ
+abl
 e;%0Aimpor
@@ -259,26 +259,21 @@
 ations.O
-nDepsChang
+bserv
 e;%0A%0A@Are
@@ -973,24 +973,8 @@
  %7D%0A%0A
-  @OnDepsChange%0A
   vo

Remove unnecessary annotation