Thursday, December 14, 2017

Agera - Functional Reactive Programming for Android

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 whenwhere 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.

second question comes to any mind is 

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

Lets start with simplest example of programming world, that is 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:

Observable.java
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 poked
  • Updatable => Called when an event has occurred. Its update() 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 the get() method is called. In this case, "Data" can be anything.
  • Receiver => Something that can receive (and normally store) a value send to it via accept().
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...!!

let's connect to learn together







No comments:

Post a Comment