### Implement and Use a Grox Command for Asynchronous Operations in Java Source: https://github.com/groupon/grox/blob/master/README.md This example illustrates how to define a 'Command' in Grox, specifically 'RefreshResultCommand', to encapsulate asynchronous operations like fetching data from a server using RxJava. It shows how to map results and errors into 'Action' objects and dispatch them to the store. The snippet also demonstrates how to trigger this command from a UI event (button clicks) and manage subscriptions. Note that such a command should be unsubscribed from when the UI element (e.g. an activity) containing the button will no longer be alive to prevent Rx chain leaks. ```Java public class RefreshResultCommand implements Command { @Override public Observable actions() { return getResultFromServer() //via retrofit .subscribeOn(io()) .map(ChangeResultAction::new) //convert all your results into actions .cast(Action.class) .onErrorReturn(ErrorAction::new) //including errors .startWith(fromCallable(RefreshAction::new)); //and progress } } //then use your command via Rx + RxBinding subscriptions.add( clicks(button) .map(click -> new RefreshResultCommand()) .flatMap(Command::actions) .subscribe(store::dispatch)); ``` -------------------------------- ### Initialize Grox Store and Dispatch Basic Action in Java Source: https://github.com/groupon/grox/blob/master/README.md This snippet demonstrates the fundamental usage of Grox by creating a 'Store' with an initial state, subscribing to state changes to update the UI (e.g., printing to console), and dispatching a simple action to modify the store's state. ```Java //create a store with an initial state Store store = new Store<>("Hello"); //when the store's state changes, update your UI states(store).subscribe(System.out::println); //start dispatching actions to your store... store.dispatch(oldState -> oldState + " Grox"); ``` -------------------------------- ### Automated Commands for Gradle Project Release Workflow Source: https://github.com/groupon/grox/blob/master/RELEASING.md This snippet provides the executable commands for a Gradle project release workflow. It assumes prior manual steps like updating `gradle.properties` (to a non-SNAPSHOT version and then to the next SNAPSHOT version) and `CHANGELOG.md`. A critical manual step involves visiting Sonatype Nexus to promote the artifact after `uploadArchives`. The commands cover committing release preparations, uploading artifacts, tagging the release, preparing for the next development version, and pushing all changes and tags. ```Git git commit -am "Prepare for release X.Y.Z." ``` ```Gradle ./gradlew clean uploadArchives ``` ```Git git tag -a X.Y.Z -m "Version X.Y.Z" ``` ```Git git commit -am "Prepare next development version." ``` ```Git git push && git push --tags ``` -------------------------------- ### Add Grox Dependencies to Gradle Project Source: https://github.com/groupon/grox/blob/master/README.md This snippet provides the necessary Gradle 'implementation' dependencies to integrate Grox into an Android or Java project. It includes the core Grox library with Rx support and the Grox commands artifacts for both RxJava 1 and RxJava 2, noting that the core library can also be used without Rx dependencies. ```Groovy //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' ``` -------------------------------- ### Execute Grox Commands Independently of UI Lifecycle in Java Source: https://github.com/groupon/grox/blob/master/README.md This snippet shows an alternative way to execute Grox commands, allowing them to persist and update the store even across configuration changes (e.g., screen rotations) by preserving the store. Only the outer subscription needs to be managed with the UI lifecycle, while the inner command chain can continue to operate, updating the store which then reflects the latest state when the UI reconnects. ```Java //then use your command via Rx + RxBinding subscriptions.add( clicks(button) .subscribe(click -> new RefreshResultCommand() .actions() .subscribe(store::dispatch))); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.