Grox helps to maintain the state of Java / Android apps.

Understanding Grox

Grox Overview


Grox video

We have a nice video to explain how the Grox sample app works.


Visit the Grox wiki

Grox in a nutshell

Grox provides developers with the basic bricks to:

Basic Usage

Very simple example:

//create a store with an initial state
Store<String> store = new Store<>("Hello");
//when the store's state changes, update your UI
//start dispatching actions to your store...
store.dispatch(oldState -> oldState + " Grox");

A command example

public class RefreshResultCommand implements Command {
  public Observable<Action> actions() {
    return getResultFromServer() //via retrofit
        .map(ChangeResultAction::new) //convert all your results into actions
        .onErrorReturn(ErrorAction::new) //including errors
        .startWith(fromCallable(RefreshAction::new)); //and progress

//then use your command via Rx + RxBinding
            .map(click -> new RefreshResultCommand())

Note that such a command should be unsubscribed from when the UI element (e.g. an activity) containing the button button will no longer be alive. Otherwise, the Rx chain would leak it.

However, if you preserve your store accross configuration changes (using ViewModels, Dependency Injection (Toothpick/Dagger), retained fragments, etc.), you can also execute commands independently of the lifecycle of the UI:

//then use your command via Rx + RxBinding
            .subscribe(click -> new RefreshResultCommand()

In this case, only the outer chain needs to be unsubcribed from when the UI elements are not alive anymore, the inner chain will be preserved during rotation and udpate the store even during a configuration change (e.g. a rotation), and the UI will display the latest when connecting to the store when the rotation is complete. A fine grained management of resources would unsubscribe from the inner chain when the store is not alive anymore.

Browse Grox sample for more details.


    //note that Grox is also available without Rx dependencies
    implementation 'com.groupon.grox:grox-core-rx:x.y.z'
    //Grox commands artifacts do depend on Rx (1 or 2)
    implementation 'com.groupon.grox:grox-commands-rx:x.y.z'
    implementation 'com.groupon.grox:grox-commands-rx2:x.y.z'

Main features

The main features of Grox are:


Conferences, talks & articles


The following people have been active contributors to the first version of Grox:

Inspired by

Grox - Java library for state management, inspired by Flux, Redux, Cycle, and Rx Managed State.