Skip to content

Commit

Permalink
Merge pull request #33 from izumin5210/release/v0.5.0
Browse files Browse the repository at this point in the history
Release v0.5.0
  • Loading branch information
Masayuki IZUMI committed Dec 6, 2015
2 parents b864130 + 41793ad commit c1594c0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 31 deletions.
83 changes: 53 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'io.reactivex:rxjava:1.0.16'
compile 'info.izumin.android:droidux:0.4.0'
apt 'info.izumin.android:droidux:0.4.0'
compile 'io.reactivex:rxjava:1.1.0'
compile 'info.izumin.android:droidux:0.5.0'
apt 'info.izumin.android:droidux:0.5.0'
}
```

Expand Down Expand Up @@ -116,10 +116,9 @@ public class CounterReducer {
* Droidux generates an implementation of getter method, observe method and dispatch method from user-defined interface.
*/
@Store(CounterReducer.class)
public interface CounterStore {
Counter counter();
public interface CounterStore extends BaseStore {
Counter getCounter();
Observable<Counter> observeCounter();
Observable<Action> dispatch(Action action);
}

/**
Expand All @@ -139,10 +138,9 @@ public class ClearCountAction implements Action {}
// Its APIs in this example are following:
// - rx.Observable<Action> dispatch(Action action)
// - rx.Observable<Counter> observeCounter()
// - Counter counter()
// - Counter getCounter()
CounterStore store = DroiduxCounterStore.builder()
.setReducer(new CounterReducer())
.setInitialState(new Counter(0))
.setReducer(new CounterReducer(), new Counter(0))
.build(); // Counter: 0

// You can observe to the updates using RxJava interface.
Expand All @@ -158,24 +156,58 @@ store.dispatch(new DecrementCountAction()).subscribe(); // Counter: 2
store.dispatch(new ClearCountAction()).subscribe(); // Counter: 0
```

### Data Binding

```java
@Store(CounterReducer.class)
public interface CounterStore extends BaseStore {
// You should annotate the getter method with @Bindable
@Bindable Counter getCounter();
}

CounterStore store = DroiduxCounterStore.builder()
// Pass the field id generated by DataBinding annotation processor.
.setReducer(new CounterReducer(), new Counter(0), BR.counter)
.build();
```

Layout file is following:

```xml
<layout>
<data>
<variable android:name="store" android:type="CounterStore" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@{store.counter}" />

</RelativeLayout>
</layout>
```


### Combined store

```java
@Store({CounterReducer.class, TodoListReducer.class})
class RootStore {
Counter counter();
class RootStore extends BaseStore {
Counter getCounter();
Observable<Counter> observeCounter();
TodoList todoList();
TodoList getTodoList();
Observable<TodoList> observeTodoList();
Observable<Action> dispatch(Action action);
}


RootStore store = DroiduxRootStore.builder()
.setReducer(new CounterReducer())
.setInitialState(new Counter(0))
.setReducer(new TodoListReducer())
.setInitialState(new TodoList())
.setReducer(new CounterReducer(), new Counter(0))
.setReducer(new TodoListReducer(), new TodoList())
.addMiddleware(new Logger())
.build();

Expand Down Expand Up @@ -203,8 +235,7 @@ class Logger extends Middleware<CounterStore> {

// Instantiate store class
CounterStore store = DroiduxCounterStore.builder()
.setReducer(new CounterReducer())
.setInitialState(new Counter(0))
.setReducer(new CounterReducer(), new Counter(0))
.addMiddleware(new Logger()) // apply logger middleware
.build(); // Counter: 0

Expand Down Expand Up @@ -259,7 +290,6 @@ class TodoListReducer {
public interface TodoListStore {
TodoList todoList();
Observable<TodoList> observeTodoList();
Observable<Action> dispatch(Action action);
}

class AddTodoAction implements Action {
Expand All @@ -272,8 +302,7 @@ class CompleteTodoAction implements Action {


TodoListStore store = DroiduxTodoListStore.builder()
.setReducer(new TodoListReducer())
.setInitialState(new TodoList())
.setReducer(new TodoListReducer(), new TodoList())
.build();

store.dispatch(new AddTodoAction("item 1")).subscribe(); // ["item 1"]
Expand Down Expand Up @@ -327,24 +356,18 @@ class ReceiveTodoListAction implements Action {


TodoListStore store = DroiduxTodoListStore.builder()
.setReducer(new TodoListReducer())
.setInitialState(new TodoList())
.setReducer(new TodoListReducer(), new TodoList())
.addMiddleware(new ThunkMiddleware())
.build();


store.dispatch(new FetchTodoListAction(client)).subscribe();
```

### Bindable methods

* `Store#getState()`
* `Store#isUndoalble()` // when the reducer is annotated with `@Undoable`
* `Store#isRedoalble()` // when the reducer is annotated with `@Undoable`


## Examples

* [Counter](https://github.com/izumin5210/Droidux/tree/master/examples/counter)
* [TodoMVC](https://github.com/izumin5210/Droidux/tree/master/examples/todomvc)
* [Todos with Undo](https://github.com/izumin5210/Droidux/tree/master/examples/todos-with-undo)
* [Todos with Dagger 2](https://github.com/izumin5210/Droidux/tree/master/examples/todos-with-dagger)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ task clean(type: Delete) {

ext {
def versionMajor = 0
def versionMinor = 4
def versionMinor = 5
def versionPatch = 0
version = "${versionMajor}.${versionMinor}.${versionPatch}"

Expand Down

0 comments on commit c1594c0

Please sign in to comment.