Skip to content

z_ext_Agera base interface

yanlu edited this page Jun 1, 2016 · 1 revision

The Example:

 mRepository = Repositories.repositoryWithInitialValue(Result.<List<GirlInfo>>absent())
         .observe(mObservable)
         .onUpdatesPerLoop()
         .goTo(networkExecutor)
         .getFrom(new GirlsSupplier(new Supplier<Integer>() {
             @NonNull
             @Override
             public Integer get() {
                 return mPagination;
             }
         }))
         .thenTransform(new Function<Result<ApiResult<GirlInfo>>, Result<List<GirlInfo>>>() {
             @NonNull
             @Override
             public Result<List<GirlInfo>> apply(@NonNull Result<ApiResult<GirlInfo>> input) {
                 if (input.succeeded() && !input.get().error) {
                     return Result.success(input.get().results);
                 } else {
                     return Result.absent();
                 }
             }
         })
         .onDeactivation(RepositoryConfig.SEND_INTERRUPT)
         .compile();

need familiar with these:

//Observable
public interface Observable {

  void addUpdatable(@NonNull Updatable updatable);
  void removeUpdatable(@NonNull Updatable updatable);
}

//Updatable
public interface Updatable {

  void update();
}

//Supplier
public interface Supplier<T> {

  T get();
}

//Function
public interface Function<TFrom, TTo> {

  TTo apply(@NonNull TFrom input);
}

//Merger
public interface Merger<TFirst, TSecond, TTo> {

  TTo merge(@NonNull TFirst first, @NonNull TSecond second);
}

//Receiver
public interface Receiver<T> {

  void accept(@NonNull T value);
}

//Predicate
public interface Predicate<T> {

  boolean apply(@NonNull T value);
}

//Repository extends Observable, Supplier<T>
public interface Repository<T> extends Observable, Supplier<T> {

  void addUpdatable(@NonNull Updatable updatable);
  void removeUpdatable(@NonNull Updatable updatable);
  T get();
}

//MutableRepository extends Repository<T>, Receiver<T>
public interface MutableRepository<T> extends Repository<T>, Receiver<T> {

  void addUpdatable(@NonNull Updatable updatable);
  void removeUpdatable(@NonNull Updatable updatable);
  T get();
  void accept(@NonNull T value);
}

//Reservoir extends Receiver<T>, Repository<Result<T>>
public interface Reservoir<T> extends Receiver<T>, Repository<Result<T>> {

  void accept(@NonNull T value);
  void addUpdatable(@NonNull Updatable updatable);
  void removeUpdatable(@NonNull Updatable updatable);
  T get();
}