Skip to content

Commit

Permalink
Fix Todo-with-dagger
Browse files Browse the repository at this point in the history
  • Loading branch information
wakwak3125 committed Jan 2, 2018
1 parent a5626a8 commit d8010ad
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public class TodoListReducer {

@Dispatchable(AddTodoAction.class)
public TodoList add(TodoList state, AddTodoAction action) {
if (state.isEmpty()) {
TodoList newState = new TodoList(state);
newState.add(new TodoList.Todo(0, action.getText()));
return newState;
}
int id = Observable.fromIterable(state)
.reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo)
.onErrorReturn(throwable -> new TodoList.Todo(0, ""))
.toObservable()
.blockingLast()
.blockingGet()
.getId();
TodoList newState = new TodoList(state);
newState.add(new TodoList.Todo(id + 1, action.getText()));
Expand Down

0 comments on commit d8010ad

Please sign in to comment.