Skip to content

Commit

Permalink
Merge pull request #11 from izumin5210/release/v0.3.0
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
Masayuki IZUMI committed Nov 24, 2015
2 parents 46c4033 + 1c3b933 commit 17bc738
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
77 changes: 73 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ Add to your project build.gradle file:
```groovy
buildscript {
dependencies {
classpath "com.android.databinding:dataBinder:1.0-rc3"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.android.databinding'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'info.izumin.android:droidux:0.2.0'
apt 'info.izumin.android:droidux:0.2.0'
compile 'info.izumin.android:droidux:0.3.0'
apt 'info.izumin.android:droidux:0.3.0'
}
```

And also you need to setup [Data Binding][databinding].


## Usage
### Quick example

Expand Down Expand Up @@ -204,6 +206,64 @@ store.dispatch(new ClearCountAction()).subscribe();
// [next counter]: 0
```

### Undo / Redo

```java
@Undoable
@Reducer(TodoList.class)
class TodoListReducer {
@Dispatchable(AddTodoAction.class)
public TodoList addTodo(TodoList state, AddTodoAction action) {
// ...
}

@Dispatchable(CompleteTodoAction.class)
public TodoList completeTodo(TodoList state, CompleteTodoAction action) {
// ...
}
}

class TodoList extends ArrayList<TodoList.Todo> implements UndoableStore {
@Override
public TodoList clone() {
// ...
}

public static Todo {
// ...
}
}

class AddTodoAction extends Action{
// ...
}

class CompleteTodoAction extends Action{
// ...
}


DroiduxTodoListStore store = new DroiduxTodoListStore.Builder()
.addReducer(new TodoListReducer())
.addInitialState(new TodoList())
.build();

store.dispatch(new AddTodoAction("item 1")).subscribe(); // ["item 1"]
store.dispatch(new AddTodoAction("item 2")).subscribe(); // ["item 1", "item 2"]
store.dispatch(new AddTodoAction("item 3")).subscribe(); // ["item 1", "item 2", "item 3"]
store.dispatch(new CompleteTodoAction("item 2")).subscribe(); // ["item 1", "item 3"]
store.dispatch(new AddTodoAction("item 4")).subscribe(); // ["item 1", "item 3", "item 4"]

store.dispatch(new UndoAction(DroiduxTodoListStore.class)).subscribe();
// => ["item 1", "item 3"]

store.dispatch(new UndoAction(DroiduxTodoListStore.class)).subscribe();
// => ["item 1", "item 2", "item 3"]

store.dispatch(new RedoAction(DroiduxTodoListStore.class)).subscribe();
// => ["item 1", "item 3"]
```

### Async action

```java
Expand All @@ -224,9 +284,18 @@ class FetchTodoListAction extends Action {
new FetchTodoAction().fetch().flatMap(store::dispatch).subscribe();
```

### Bindable methods

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


## Examples

* [TodoMVC](https://github.com/izumin5210/Droidux/tree/master/examples/todomvc)
* [Todos with Undo](https://github.com/izumin5210/Droidux/tree/master/examples/todos-with-undo)


## License

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ task clean(type: Delete) {

ext {
def versionMajor = 0
def versionMinor = 2
def versionMinor = 3
def versionPatch = 0
def versionBuild = 0

Expand Down
4 changes: 2 additions & 2 deletions examples/todomvc/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources>
<string name="app_name">Droidux sample</string>
<string name="title_activity_main">Droidux sample</string>
<string name="app_name">TodoMVC</string>
<string name="title_activity_main">TodoMVC</string>

<string name="btn_add_todo">Add</string>
<string name="edit_new_todo_hint">new task</string>
Expand Down

0 comments on commit 17bc738

Please sign in to comment.