What is Agera?
Agera is a super lightweight Android library that helps prepare data for consumption by the Android application components (such as Activities), or objects therein (such as Views), that have life-cycles in one form or another.
It introduces a flavor of functional reactive programming, facilitates clear separation of the when, where and what factors of a data processing flow, and enables describing such a complex and asynchronous flow with a single expression, in near natural language.
What do we mean by reactive?
Reactive programming is a paradigm related to how changes are propagated in a program. A good example is a spreadsheet: cells contain formulas that depend on other cells' values. When one of these values are changed, there's no need to manually update the resulting values; the changes are propagated for you. Agera brings a reactive flavor to Android using an observer pattern.
Hello World Example
But to learn how to code for "Hello World", we need to learn basic components of Agera.
The foundation of Agera is a set of very simple interfaces including: Observable, Updatable, Supplier and Receiver:
public interface Observable {
void addUpdatable(Updatable updatable);
void removeUpdatable(Updatable updatable);
}
Updatable.java
public interface Updatable {
void update();
}
Supplier.java
public interface Supplier<T> {
T get();
}
Receiver.java
public interface Receiver<T> {
void accept(T value);
}
As you can see, these four interfaces are very simple. This is what they're responsible for:
Observable
=> Something that can be observed for changes and stores a list of updatable objects. When a change occurs, the updatables are pokedUpdatable
=> Called when an event has occurred. Itsupdate()
method will be called when the class it observes changes, but can also be called manually to force an update.Supplier
=> Something that supplies data when theget()
method is called. In this case, "Data" can be anything.Receiver
=> Something that can receive (and normally store) a value send to it viaaccept()
.
lets see how to use them in our code.
I have already written Hello World Example on Github
All the best !!! Happy Coding !!!
Next Step is to learn Repository..
Repository
=> The most important concept in Agera is the Repository. Repositories receive, supply, and store data and emit updates. The interfaces Observable, Supplier and Receiver are combined into two types of repositories: Repository can replace Observable and Supplier
MutableRepository can replace Observable, Supplier and Receiver
A complete blogpost is coming soon on Repository...!!
No comments:
Post a Comment