Skip to content

Commit

Permalink
bumped version, add changes, add reductor-observable readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarikx committed Jan 2, 2017
1 parent cef350d commit 8b51c25
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Reductor Releases #

### Version 0.13.0 - January 2, 2017

#### New Module: ReductorObservable

Added [ReductorObservable](https://github.com/Yarikx/reductor/tree/master/reductor-observable) module that mimics [redux-observable](https://github.com/redux-observable/redux-observable).
This allows to dispatch async actions and do side-effects in composable way using RxJava.

### Version 0.12.0 - December 17, 2016

#### New feature: Dispatcher and Cursor
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
project.ext {
bintrayUser = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : ""
bintrayKey = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : ""
reductorVersion = '0.12.0'
reductorVersion = '0.13.0'
}


Expand Down
45 changes: 45 additions & 0 deletions reductor-observable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Reductor Observable

Combine RxJava streams to dispatch async actions and handle side effects.

### Epic

The core primitive is `Epic`. Epic is defined as a simple interface:

```java
public interface Epic<T> {
Observable<Object> run(Observable<Action> actions, Store<T> store);
}
```

Epic is run once `Store` is created.
It's basically a function that takes a stream of actions and returns stream of actions.
Each object emitted by returned Observable will be dispatched back to `Store`.

A simple example of async flow is Ping-Pong Epic which listens for `PING` action and responds with `PONG` after one second.

```java
Epic<String> pingPongEpic = (actions, store) ->
actions.filter(Epics.ofType("PING"))
.delay(1, TimeUnit.SECONDS)
.map(action -> Action.create("PONG"));
```

Each 'PONG' message will be dispatched back to store to be handled by `Reducer`.

### Creating Middleware

To connect `Epic` to `Store`, create `EpicMiddleware` with provided epic.
Once middleware is created, it can be passed to `Store.create`:

```java
EpicMiddleware<String> middleware = EpicMiddleware.create(pingPongEpic);

Store<String> store = Store.create(reducer, middleware);
```

#### Combining epics

EpicMiddleware takes only one rootEpic in `EpicMiddleware.create`.
However, you can combine more than one epics into single Epic by using `Epics.combineEpics(epics)`.
This will simply merge all returned streams into one.
2 changes: 1 addition & 1 deletion reductor-observable/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'
//apply from: '../gradle/publishing.gradle'
apply from: '../gradle/publishing.gradle'
apply from: '../gradle/jacoco.gradle'

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* <p>
* Ping-Pong example:
* <pre><code>
* Epic<String> pingPong = (actions, store) ->
* Epic&lt;String&gt; pingPong = (actions, store) -&gt;
* actions.filter(Epics.ofType("PING"))
* .delay(1, TimeUnit.SECONDS)
* .map(action -> Action.create("PONG"));
* .map(action -&gt; Action.create("PONG"));
* </code></pre>
*
* @param <T> state type of {@link Store}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import rx.observers.TestSubscriber;
import rx.subjects.PublishSubject;

import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -80,11 +78,4 @@ public void testUnsubscriptionEpic() {
assertFalse("epic observable is unsubscibed after middleware.unsubscribe", epicObservable.hasObservers());
}

public void pingpong() {
Epic<String> pingPong = (actions, store) ->
actions.filter(Epics.ofType("PING"))
.delay(1, TimeUnit.SECONDS)
.map(action -> Action.create("PONG"));
}

}

0 comments on commit 8b51c25

Please sign in to comment.