-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bumped version, add changes, add reductor-observable readme
- Loading branch information
Showing
6 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters